C++
Can destru ...
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
Can destructors be virtual?
Yes
No
Explanation
Every destructor down gets called no matter what.
virtual
makes sure it starts at the top instead of the middle. Read more at
this stackoverflow answer
.
destructor
virtual
Like
Login in
to like
Comment
Login in
to comment
Share
Tweet
Related Content
Что выведет следующий код? #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; }
Как порядок вызова конструкторов и деструкторов повлияет на результат и что выведется на экран? #include <iostream> using namespace std; struct A { A() { cout << "A"; } ~A() { cout << "~A"; } virtual void operator()() = 0; }; struct B : A { B() { cout << "B"; } ~B() { cout << "~B"; } void operator()() { cout << "B"; } }; int main(void) { B b; A &a = b; a(); b(); return 0; }
Имея следующую иерархию классов, что будет выведено на экран при выполнении следующего кода? #include <iostream> using namespace std; class Agregated{ public: Agregated(){ cout<<"Agregated construct"<<endl; } ~Agregated(){ cout<<"Agregated destruct"<<endl; } }; class Base{ protected: Agregated * ptr; public: Base():ptr(NULL){ cout<<"Base construct"<<endl; f(); } virtual ~Base()=0; virtual void f()=0; }; Base::~Base(){ if(ptr) delete ptr; cout<<"Base destruct"<<endl; } void Base::f(){ cout<<"Base f"<<endl; } class Derived: public Base{ public: Derived(){ if(!ptr) ptr = new Agregated; cout<<"Derived construct"<<endl; } ~Derived(){ cout<<"Derived destruct"<<endl; } void f(){} }; int main(){ Base* b = new Derived(); delete b; cin.get(); return 0; }
Что будет выведено на экран в результате выполнения такого кода: #include <iostream> struct A { ~A() { std::cout << "~A"; }; }; struct B: public A { virtual ~B() { std::cout << "~B"; }; }; int main() { A *a = new B(); delete a; return 0; }
Что выведет на консоль следующий программный код? #include <iostream> class Base { public: virtual void Foo() { std::cout << "Base::Foo "; } virtual ~Base() {} }; class Derived: public Base { public: int Foo() { std::cout << "Derived::Foo "; return int();} }; int main() { Base *d = new Derived; d->Foo(); delete d; return 0; }
C
++
Quiz
Login to learn C++
or
Read more about
C++ Quizzes
Follow CodeGalaxy
Mobile Beta
Send Feedback
Keep exploring
C++ quizzes
int main() { const int* i = int(); // 1 int const* j = int(); //2 int* const k = int(); //3 int* l(); //4 ++i; //5 ++j; //6 ++k; //7 ++*k; //8 ++l; //9 } Откомпилируется ли такой код? Если нет, то в каких строчках будут ошибки компиляции? После стандарта C++14.
Какой результат работы программы? #include <iostream> using namespace std; void f(double) { cout<<"f1"<<endl; } void f(const int ) { cout<<"f2"<<endl; } void f( int & ) { cout<<"f3"<<endl; } void main(void) { int n = 1; double b = 2; f(n); f(b); }
#include <iostream> using namespace std; int &test() { static int a = 3; return a; } int main() { ++++++test(); cout << test() << endl; return 0; } Что выведет cout?
При истинности какого из приведенных высказываний имеет смысл вычитание указателей?
Какое ключевое слово используется для описания пространства имен?
В чем разница между X x; и X x(); ?
Sign Up Now
or
Subscribe for future quizzes
Login in to like
Login in to comment