第2个回答 2011-04-24
构造函数分带参数和不带参数的两种。
例如:
不带参数的:
class Time
{public :
Time( )//l类内定义无参数构造函数
{hour=0;
minute=0;
sec=0;
}
带参数的:
class Box
{public :
Box(int,int,int);
int volume( );
private :
int height;
int width;
int length;
};
Box::Box(int h,int w,int len) //在类外定义带参数的构造函数
{height=h;
width=w;
length=len;
}
如果采用的是带参数的构造函数,则因该注意参数的个数问题,正确使用编译不会出错的。