I have a class:
class A
{
public:
A()
{
std::cout << "Constructor called" << std::endl;
}
~A()
{
std::cout << "Destructor called" << std::endl;
}
A(const A& another)
{
std::cout << "Copy constructor called" << std::endl;
}
A& operator=(const A& another)
{
std::cout << "Assignment operator= called" << std::endl;
}
};
In my very complicated project, I got the following output after I started my app:
Constructor called
but when I Ctrl+C to terminate my app:
Destructor called
Destructor called
And in the whole process, no copy constructor or assignment operator got called.
My class A has dynamic memory allocation, and I have to free it in the destructor, but the destructor is called twice somehow, which is very bad.
I don't know what could cause this problem.
I googled and searched a lot. A lot of questions about "destructor called twice" is because of the the implicit calling of the copy constructor (assignment operator).
Thanks.
Peter
operator=or am I missing something ? - ereOnAis used in your code? - Gregg