c++虚拟成员函数
来源:互联网 发布:线程优化 编辑:程序博客网 时间:2024/05/20 06:06
// virtual members#include <iostream>using namespace std;class Polygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; } virtual int area () { return 0; }};class Rectangle: public Polygon { public: int area () { return width * height; }};class Triangle: public Polygon { public: int area () { return (width * height / 2); }};int main () { Rectangle rect; Triangle trgl; Polygon poly; Polygon * ppoly1 = ▭ Polygon * ppoly2 = &trgl; Polygon * ppoly3 = &poly; ppoly1->set_values (4,5); ppoly2->set_values (4,5); ppoly3->set_values (4,5); cout << ppoly1->area() << '\n'; cout << ppoly2->area() << '\n'; cout << ppoly3->area() << '\n'; return 0;}
阅读全文
0 0
- 4.2 虚拟成员函数
- c++虚拟成员函数
- More Effective C++----技巧 & (25)将构造函数和非成员函数虚拟化
- 【C++】深度探索C++对象模型之虚拟成员函数(virtual member function)
- c++const成员函数
- C++_const成员函数
- [C++] 静态成员函数
- C++:特殊成员函数
- 4.1 成员函数的各种调用方式(静态成员函数,非静态成员函数,虚拟成员函数)
- c++static数据成员和成员函数
- 将构造函数和非成员函数虚拟化
- 8.将构造函数和非成员函数“虚拟化”
- 将构造函数和非成员函数虚拟化
- C++static静态成员函数
- C++:类的成员函数
- C++—特殊成员函数
- 【C++】静态成员函数小结
- C++——成员函数
- 各种滤波算法的比较
- 二叉树
- luogu1020 导弹拦截
- Windows10+Visual Studio2013+caffe GPU+CPU环境详细配置
- Java代码将数据导出到Excel
- c++虚拟成员函数
- 事件深入应用
- EditPlus-注册码
- 校内八连测 第一试
- 使用web.py接收post数据时中文变成&#xxxxx;的问题
- 浅谈安卓框架mvp
- Spring AMQP 1.6完整参考指南-第二部分
- vm虚拟机centos7桥接模式连接外网
- 236. Lowest Common Ancestor of a Binary Tree