我是靠谱客的博主 感性咖啡,这篇文章主要介绍c++——指向类的指针,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream> using namespace std; class Box { public: Box(double l=2.0,double b=2.0,double h=2.0) { cout << "constructor called" << endl; length = l; breadth = b; height = h; } double Volume() { return length * breadth*height; } private: double length; double breadth; double height; }; int main() { Box box1(2.0,1.0,2.0); Box box2(2.1, 1.2, 2.3); Box* ptrBox; ptrBox = &box1; cout << "Volume of box1:" << ptrBox->Volume() << endl; ptrBox = &box2; cout << "Volume of box2:" << ptrBox->Volume() << endl; return 0; }

在这里插入图片描述

最后

以上就是感性咖啡最近收集整理的关于c++——指向类的指针的全部内容,更多相关c++——指向类内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部