首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

类的实现,该怎么处理

2012-03-18 
类的实现在头文件中定义一个有默认参数的构造函数,然后在gx.cpp中是gx类的实现,这样定义为什么出错了,如果

类的实现
在头文件中定义一个有默认参数的构造函数,然后在gx.cpp中是gx类的实现,这样定义为什么出错了,如果要定义一个有默认参数的构造函数的类,且要分开实现,应该怎么做啊?谢谢!

//gx.h
#include <iostream.h>

class   gx
{
public:
gx(int   a=5,int   b=5);

void   show();
private:
int   length;
int   width;
};

//gx.cpp
#include <iostream.h>
#include "gx.h "
gx::gx(int   a=5,int   b=5);
{
//int   a,b;
//cout < < "input   two   number: " < <endl;
//cin> > a> > b;
width=b;
length=a;
}
void   gx::show()
{
cout < < "the   length   is: " < <length < <endl;
cout < < "the   width   is: " < <width < <endl;
cout < < "the   mj   is: " < <length*width < <endl;
}

[解决办法]
//gx.cpp
#include <iostream.h>
#include "gx.h "
gx::gx(int a,int b); /////把=5去掉
{
//int a,b;
//cout < < "input two number: " < <endl;
//cin> > a> > b;
width=b;
length=a;
}

热点排行