Hello ,
Iam using borland 2006 c++
class A
{
private:
TObjectList* list;
int myid;
public:
__fastcall A(int);
__fastcall ~A();
};
__fastcall A::A(int num)
{
myid = num;
list = new TObjectList();
}
__fastcall A::~A()
{
}
int main(int argc, char* argv[])
{
myfunc();
return 0;
}
void myfunc()
{
vector<A> vec;
vec.push_back(A(1));
}
when i add a new object A to the vector, it calls its destructor twice, and then once when vec goes out of scope , so in total 3 times.
I was thinking it should call once when object is added, and then once when vec goes out scope.