class Rectangel
{
public:
//无返回值
Rectangel(int l,int w){
length=l;
width=w;
}
int area(){return length*width;}
private:
int length,width;
};
使用:
int main()
{
Rectangel rectangel(3,4);
cout<
若写了构造函数,则系统不再提供默认构造函数,可加多个不同参数的构造函数。与Java最大的区别是,不需要用new了