您的位置:首页 > 编程语言 > C语言/C++

C++ overloading contructor

2016-01-18 10:44 441 查看

// overloading class constructors
#include <iostream>
using namespace std;

class Rectangle {
int width, height;
public:
Rectangle ();
Rectangle (int,int);
int area (void) {return (width*height);}
};

Rectangle::Rectangle () {
width = 5;
height = 5;
}

Rectangle::Rectangle (int a, int b) {
width = a;
height = b;
}

int main () {
Rectangle rect (3,4);
Rectangle rectb;
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: