C++ object/pointer construction/deconstruction
#include <iostream>
using namespace std;
class A
{
public:
char label;
A()
{
label = 'X';
}
A(char l)
{
label = l;
cout << "Constructing " << label << endl;
}
~A()
{
cout << "Deconstructing " << label << endl;
}
};
int main()
{
A a('a');
A *b;
A *c = new A('c');
A *d = new A('d');
delete d;
return 0;
}
Output:
Constructing a Constructing c Constructing d Deconstructing d Deconstructing a
Advertisement