// 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++ overloading contructor
转载
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C++ 重载overloading 重写override
重载 overloading 重写override
重载 overloading 重写override -
Java:Overriding与Overloading
在Java中,什么是Overriding?什么是Overloading?
java Overriding Overloading -
Operator Overloading part 2(Chapter 12 of Thinking in C++)
[代码]
C++ #include ios 学习 -
Function Overloading & Default Arguments(Chapter 7 of Thinking in C++)
Mem.hCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1#ifndefMEM_H2#defineMEM_H3typedefunsignedcharbyte;45classMem6{7byte*mem;8intsize;9voidensureMinS...
C++ #include ios #define #ifndef