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 method table
:
Content language: Русский
English
Какой из двух классов занимает больше памяти в C++: class A{ int i; int foo(int a); }; Class B{ int i; virtual int boom(int b); };
virtual method table
Что будет выведено на экран? 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 method table
Что выведет такой код? #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 method table
Что выведет следующий код? #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 method table
Могут ли следующие выражения сравнения приведённых указателей быть верными ? (IX*)this != (IY*) this //1 (void*)this != (IY*) this //2
virtual method table
Что будет выведено на консоль в результате выполнения программы? #include <iostream> struct A { char foo() { return 'A';} }; template<class T> struct B : public T { virtual char foo() {return 'B';} }; template<class T> struct C : public T { virtual char foo() {return 'C';} }; int main(int argc, char* argv[]) { A* a = new A(); A* b = new B< A >(); A* c = new C< A >(); A* d = new B< C< A > >(); std::cout << a->foo() << b->foo() << c->foo() << d->foo(); return 0; }
virtual method table
Что выведет программа? #include <iostream> using namespace std; class a { private: virtual void f(int) { cout<<"a int"; } }; class b : public a { public: class a; friend void f(double) { cout<<"b double"; } void f(int) { cout<<"b int"; } }; int main (void) { b* o = new b; o->f(0.5); return 0; }
virtual method table
В некоторых источниках советуют инициализировать нулём поля экземпляра структуры. Как поведет себя следующий фрагмент кода при компиляции, при запуске? #include <iostream> #include <typeinfo> using namespace std; class A { public: virtual const type_info& Type() { return typeid(*this); } }; struct B : public A { public: int field1; int field2; int field3; B() { memset(this, 0, sizeof(B)); } }; int main() { A* b = new B(); cout << b->Type().name(); return 0; }
virtual method table
Что произойдет при компиляции и выполнении программы? #include <iostream> using namespace std; class A { public: A() { CoolVirt("A()"); } ~A() { CoolVirt("~A()"); } protected: void CoolVirt(const char* str) { f(str); } virtual void f(const char* str) = 0; }; class B: public A { public: B() { CoolVirt("B()"); } ~B() { CoolVirt("~B()"); } protected: void CoolVirt(const char* str) { f(str); } void f(const char* str) { cout << str << endl; } }; int main() { B b; return 0; }
virtual method table
Что выведет на экран данная программа? #include <iostream> using namespace std; class A { public: virtual void foo(){ cout<<"A"; } }; class B: public virtual A { public: virtual void foo(){ cout<<"B"; } }; class C: public virtual A {}; class D: public B, public C {}; int main(void) { D d; C &c = d; c.foo(); return 0; }
virtual method table
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes