Chinese student seek help

G

Guest

I'm a Chinese student
I found a very confusable proble
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 resul
is below

In construct
In copy construct
In construct
In copy construct

2.If I define ~confusable( ),the resul
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

*/
 
G

Guest

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top