#include <iostream>
using namespace std;
class Box
{
private:
double length;
double width;
double height;
double volume;
public:
Box(double length,double width,double height)
{
this->length = length;
this->width = width;
this->height = height;
}
double getvolume()
{
volume = length * width * height;
return volume;
}
};
int main(void)
{
Box box1(1,2,3);
Box box2(4,5,6);
Box *p;
p = &box1;
cout<<"体积是:"<<p->getvolume()<<endl;
p = &box2;
cout<<"体积是:"<<p->getvolume()<<endl;
return 0;
}
C++指向类的指针
最新推荐文章于 2024-08-23 17:54:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)