Skip to content

Instantly share code, notes, and snippets.

@nazarov-yuriy
Created April 19, 2013 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazarov-yuriy/5423051 to your computer and use it in GitHub Desktop.
Save nazarov-yuriy/5423051 to your computer and use it in GitHub Desktop.
/*
* programm to test constructor/destructor call sequence
* programm compiled in gcc generate following output:
Constructor a
Constructor b
Constructor a
Constructor b
in function
Destructor b
Destructor a
Destructor b
Destructor a
after function
*/
#include <iostream>
#include <stdint.h>
#include <string>
using namespace std;
class a{
public:
a();
~a();
};
class b{
private:
a field_a;
public:
b();
~b();
};
a::a(){
cout << "Constructor a" << endl;
}
a::~a(){
cout << "Destructor a" << endl;
}
b::b(){
cout << "Constructor b" << endl;
}
b::~b(){
cout << "Destructor b" << endl;
}
void func_c(){
b *object_b = new b[2];
cout << "in function" << endl;
delete []object_b;
}
int main() {
func_c();
cout << "after function" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment