请看下面程序2种写法,一个是构造函数在类里面,一个在外面~!怎么只能在类里面的才通过编译~!
class Desk
{
private:
int weight;
int height;
int width;
int length;
public:
Desk(int,int,int,int);
};
Desk::Desk(int we=3,int h=4,int wi=5,int l=6)
{
weight=we;
height=h;
width=wi;
length=l;
cout<<weight<<height<<width<<length<<endl;
}
void main()
{
Desk dk1;
Desk dk2(6,5);
Desk dk3(6,5,5,5);
cout<<"Back in main"<<endl;
}
======================================================================
class Desk
{
private:
int weight;
int height;
int width;
int length;
public:
Desk(int we=3,int h=4,int wi=5,int l=6)
{
weight=we;
height=h;
width=wi;
length=l;
cout<<weight<<height<<width<<length<<endl;
}
};
void main()
{
Desk dk1;
Desk dk2(6,5);
Desk dk3(6,5,5,5);
cout<<"Back in main"<<endl;
}
===================================================================
问题是在Desk dk1;这个对象定义不能读取默认值~!