Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
virtual functions
:
Content language: Русский
English
Что выведется на экран ? #include <iostream> using namespace std; class A { public: virtual void Foo(int n = 10) { cout << "A::Foo, n = " << n << endl; } }; class B : public A{ public: virtual void Foo(int n = 20) { cout << "B::Foo, n = " << n << endl; } }; int main() { A * pa = new B(); pa->Foo(); return 0; }
virtual functions
Какой из двух классов занимает больше памяти в C++: class A{ int i; int foo(int a); }; Class B{ int i; virtual int boom(int b); };
virtual functions
Что будет выведено на экран? class A1 { public: virtual void k(){std::cout<<"A1";} }; class B1: public A1 { public: void k(){std::cout<<"B1";} }; void function(A1 a) { a.k(); } int main() { B1 b; function(b); }
virtual functions
Что выведет на экран следующая программа? #include <iostream> using namespace std; struct A { void foo() { cout << "A::foo()\n"; } }; struct B : virtual A { virtual void foo() { cout << "B::foo()\n"; } }; struct C : B, virtual A { void foo() { cout << "C::foo()\n"; } }; int main (int argc, char *argv[]) { C().foo(); A *a = new C; a->foo(); static_cast<A*>(new C)->foo(); return 0; }
virtual functions
Что выведет такой код? #include <iostream> struct A { virtual void method() const { std::cout << "A" << std::endl; } virtual ~A(){} }; struct B : A { virtual void method() { std::cout << "B" << std::endl; } }; int main() { A * ptr = new B(); ptr->method(); delete ptr; return 0; }
virtual functions
Что выведет следующий код? #include <iostream> using namespace std; struct A { virtual ~A() = 0; }; A::~A() { cout << "~A"; } struct B : A { ~B() { cout << "~B"; } }; int main() { A *a = new B; delete a; }
virtual functions
Каким будет результат разных вызовов методов класса и структуры? #include <iostream> class A { public: virtual A &Get() { std::cout << "A"; return *this; } }; struct B : A { B &Get() { std::cout << "B"; return *this; } }; int main(int, char *argv[]) { B b; A &a1(b), a2(a1), *a3(&a2), *a4(&a1); b.Get(); a1.Get(); a2.Get(); a3->Get(); a4->Get(); }
virtual functions
Могут ли следующие выражения сравнения приведённых указателей быть верными ? (IX*)this != (IY*) this //1 (void*)this != (IY*) this //2
virtual functions
Чем отличаются классы имеющие "чисто виртуальные" (pure virtual) функции?
virtual functions
Выберите правильные утверждения для следующего кода struct A { virtual void Foo() = 0; }; struct B : A { void Foo() { /*code*/ } };
virtual functions
← Prev
1
2
3
Next →
Sign Up Now
or
Subscribe for future quizzes