Copy constructor, Assignment operators

Hi,
I wrote a program and I just don't understand how it works (funny, isn't it?). Could somebody please explain?

Here is my overloaded operator +

Vektor Vektor::operator+(const Vektor& scitanec2)const
{
Vektor navrat;

for(int i=0; i<5; i++){
navrat.pole[i] = pole[i] + scitanec2.pole[i];
}

return navrat;
}

Vektor is my class, pole is public variable type: int *pole; Memory is allocated in constructor (using new).
I defined constructor, which fills the vector pole and then writes "Vector born". Copy constructor copies and writes "Vector copyied". Destructor writes "Vector dead".

My main:

Vektor* A = new Vektor;
Vektor* B = new Vektor;
Vektor* C = new Vektor(*A);

*C=*A+*B;

And what happens? In console, the program writes: Vector born, Vector copyied, Vector dead, Vector dead. That means Constructor, Copy constructor and twice Desctructor was used. Does anyone know what is really happening in the program?
Topic archived. No new replies allowed.