demo_constructor_01.cpp
来自「对于一个初涉VC++的人来书」· C++ 代码 · 共 67 行
CPP
67 行
//***************************************************
# include <iostream.h>
# include <conio.h>
class Desk
{
public:
Desk(); //构造函数
protected:
int weight;
int high;
int width;
int length;
};
class Stool
{
public:
Stool(); //构造函数
protected:
int weight;
int high;
int width;
int length;
};
Desk::Desk() //构造函数定义
{
weight=10;
high=5;
width=5;
length=5;
cout<<weight<<" "<<high<<" "
<<width<<" "<<length<<endl;
}
Stool::Stool() //构造函数定义
{
weight=6;
high=3;
width=3;
length=3;
cout<<weight<<" "<<high<<" "
<<width<<" "<<length<<endl;
}
void fn()
{
Desk da;
Stool sa;
}
void main()
{
Desk da;
Stool sa;
getch();
fn();
getch();
Desk db[2];
Stool sb[2];
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?