Hi,
I'm a Chinese student.
I found a very confusable problem
when I studied Visual C++ 6.0.
The problem is:
#include <iostream.h>
class confusable {
private:
int x,y;
public:
confusable(int x1,int y1){
x=x1; y=x1;
cout<<"In construct !\n";
}
confusable(confusable & obj){
*this=obj;
cout<<"In copy construct !\n";
}
// 下面的析构函数 有与没有 令人奇怪 !!!
//very confusable below:
//~confusable( ){ cout<<"deconstruct ... \n"; }
};
void main( )
{
{ // 为了便于观察,故意将对象数组设置 局部变量
confusable confuse[2]={ confusable(1,1),confusable(2,2) };
}
}
/*
1. If I don't define ~confusable( ),the result
is below:
In construct !
In copy construct !
In construct !
In copy construct !
2.If I define ~confusable( ),the result
is below:
In construct !
In construct !
deconstruct ...
deconstruct ...
question:
Where is the "In copy construct !"?
In my opinion,
The result should be:
"
In construct !
In copy construct !
In construct !
In copy construct !
deconstruct ...
deconstruct ..."
Please tell me why!
The reason please!!
Easily and clearly!
*/
This question You should ask in VC++ or C++ group.
As i see your copy constructor copies reference... that
isn't a good practise. As i remember from my C++ coding
in copy constructor i was copying only object fields.
First constructor code looks that it isn't do what it
should... but it doesn't matter for your output.
Regards
Marcin
PS: Try to set more descriptive mail's subject for a next time :)