C++面向对象编程 : 教程地址 :https://www.runoob.com/cplusplus/cpp-data-encapsulation.html
作者认为对面向对象的理解不能局限于本身,要作为一种思考问题的方式,高内聚低耦合. 对各种数据要进行归类汇总,集中思考,思考时要本着同类聚合建立解决模板,不同类分开确认差别,建立继承方案.基类(父类),派生类(子类).多态,模板(泛型编程),数据抽象,数据封装等
template <typename type> ret-type func-name(parameter list)
{
// 函数的主体
}
#include <iostream>
using namespace std;
class ren
{
public:
int a = 5;
public:
double getVolume(void)
{
return a*a*a;
}
};
int main()
{ int b;
ren ren1;
ren1.a = 50;
b = ren1.getVolume();
cout << "Hello, world:" << b<< endl;
return 0;
}
运行结果: Hello, world:125000