#include <iostream>
using namespace std;
class first {
int random;
public:
first() {
cout << "first created." << endl;
}
~first() {
cout << "first destroyed." << endl;
}
};
class composition {
first* firstObj;
public:
composition () {
firstObj = new first;
if (firstObj != NULL) {
cout << "firstObj points to an object of first" << endl;
}
cout << "An object of composition has been created." << endl;
}
~composition() {
delete firstObj;
cout << "composition destroyed." << endl;
}
};
int main() {
composition com;
return 0;
}
/*
Output:
first created.
firstObj points to an object of first
An object of composition has been created.
first destroyed.
composition destroyed.
With delete firsObj ommited:
first created.
firstObj points to an object of first
An object of composition has been created.
composition destroyed.
*/