ch12_1.cpp
来自「钱能的经典入门教程《C++程序设计教程》书中例程的代码」· C++ 代码 · 共 52 行
CPP
52 行
//**********************
//** ch12_1.cpp **
//**********************
#include <iostream.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; //自动调用Desk()
Stool sa; //自动调用Stool()
}
void main()
{
fn();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?