overloadcon.cpp

来自「这个是我们学校用的VC++教案」· C++ 代码 · 共 17 行

CPP
17
字号
#include  <iostream.h>
class  Box
{
private:
	int  height, width, depth;
public:    
	Box() { height=0; width=0; depth=0; }			// 避免给成员变量赋不安全的值
	Box(int  ht, int  wd, int  dp) { height=ht; width=wd; depth=dp; }	   // 重载构造函数
	int  Volume() { return  height*width*depth; }
}; 
void  main()
{
	Box  box1;
	Box  box2(10, 15, 20);
	cout<<"Volume1="<<box1.Volume()<<", Volume2="<<box2.Volume()<<endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?