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; }
相关文章推荐
- 深入C++的new
- [积累]C++复习 海大2014硕士生面试题微信系统总结
- C语言 函数理解(以数组做参数)
- C语言学习之指针第一讲
- C++入门(19):向量与迭代器
- C/C++ Summary at USC
- Sicily 1920. Divide The Stones
- #枚举和排序 B - ID Codes
- 控制流【重学C之三】
- C++编程(四)--- 代码规范
- 【C语言】实现strcat函数
- 【C语言】实现strcpy函数
- 编程题#6: priority queue练习题(C++程序设计第9周)
- 「C语言」原码反码补码与位运算
- 编程题#5: 热血格斗场(C++程序设计第9周)
- 编程题#4: 字符串操作(C++程序设计第9周)
- C++namespace
- 【C语言】实现memcopy、memmove函数
- [项目]用C++实现的壳(基础版)
- c++11 访问者模式