实例化
#include <iostream>
using namespace std
class Box
{
public:
double length;
double breadth;
double height;
double getVolume(void);
void setLength(double len);
void setBreadth(double bre);
void setHeight(double hei);
};
double Box::getVolume()
{
return length*breadth*height;
}
void Box::setLength(double len)
{
length=len;
}
void Box::setBreadth(double bre)
{
breadth=bre;
}
void Box::setHeight(double hei)
{
height=hei;
}
int main(){
Box box1;
box1.length = 5.0;
Box* pBox2 = new Box();
(*pBox2).length = 4.0;
pBox2->height = 50.0;
double length = pBox2->getVolume();
delete pBox2;
}
get、set 函数
通过private实现
构造函数
析构函数