I was trying to practice on the following code:
#include <iostream>
#include <vector>
using namespace std;
class A
{
public:
virtual void f(){cout<<"A"<<endl;}
virtual ~A(){cout<<"destruct A"<<endl;}
};
int main()
{
A o1,o2;
vector <A > O;
O.push_back(o1);
cout<<"1"<<endl;
O.push_back(o2);
cout<<"test"<<endl;
return 0;
}
The results turned out to be:
1
destruct A
test
destruct A
destruct A
destruct A
destruct A
Get confused about where the first destructor comes from.
After we had print statements to the copy constructor we get this:
So now lets look at the code: