+ 1

Constructor and destructor

why not output of the code is cadb, instead of cabd? #include <iostream> using namespace std; class A { public: A(){cout<<"a";} ~A(){cout<<"b";} }; class B { public: B(){cout<<"c";} ~B(){cout<<"d";} }; int main() { B b; A a; }

13th Jan 2021, 10:36 AM
Mayank Mishra
3 Respostas
+ 5
Objects are destroyed in reverse order in which they were constructed.
13th Jan 2021, 10:50 AM
Arsenic
Arsenic - avatar
+ 4
Post the link in the description of the Question instead of tagging and use the Tags section for tagging your programming language
13th Jan 2021, 10:42 AM
Alphin K Sajan
Alphin K Sajan - avatar
0
Now ?
13th Jan 2021, 10:45 AM
Mayank Mishra