- 0
- 0
- 约6.9千字
- 约 17页
- 2023-10-22 发布于北京
- 举报
15 Polymorphism Virtual Functions
1. Polymorphism virtual functions
2. How C++ implements late binding
3. Virtual function constructor/destructor
4. Pure virtual functions and classes
5. Summary
15.4 Pure virtual functions and classes
Sometimes you want the base class to present only an interface for its
derived classes. You don’twant any o actually create an object of the
base class. An class at least has one pure virtual function.A
pure class has nothing but pure virtual functions.
You can not create an object of the class.
class Point // class
{
public:
void show() {cout“ class”endl; }
virtual void Set()=0; // ! virtual void Set() { };
virtual void Draw()=0;
};
// Point obj ; //error
15.4 Pure virtual functions and classes
◼ When an class is inherited, all pure virtual functions should
be implemented, or the inherited class es as well.
◼ By making a class , you can ensure that a pointer or reference
is always used during upcasting to that class, to prevent object slicing.
class Point { // class
int x0,y0;
public:
Point(int i=0,int j=0) {x0=i;y0=j;}
virtual void Set()=0;
virtual void Draw()=0;
};
class Line: public Point {
int x1,y1;
public:
Line(int i=0,int j=0,int m=0,int n=0): Point(i,j) { x1=m; y1=n; }
virtual void Set() {coutLine::Set() called. endl;}
virtual void Draw() {coutLine::Draw() called. endl;}
};
15.4 Pure virtual functions and classes
// class
class Ellipse: public Point
{
int x2,y
您可能关注的文档
- sap培训时得到erpbpd en2013年9月英语.pdf
- 参考案例文案base smp user side migration guide.pdf
- e6上下料操作手册.pdf
- 内容xia 14 0692 01c发给黄延聘engineer.pdf
- 第六单元than asiajuθne z安乐死.pdf
- b投资致股东信1986.pdf
- 2026年及未来5年市场数据中国卷烟行业竞争状况及投资发展前景分析报告.docx
- 2026年及未来5年市场数据中国咖啡机行业市场运营态势与投资潜力咨询报告(定制版).docx
- 2026年及未来5年市场数据中国咖啡连锁产业深度调研与投资决策咨询报告.docx
- 2026年及未来5年市场数据中国精氨酸行业市场深度调研及发展趋势与投资前景研究报告.docx
- 三年级下册语文1-8单元默写通关训练(含答案)(2).docx
- 2026年及未来5年市场数据中国金属钒市场发展规划及投资战略可行性预测报告.docx
- 2026年及未来5年市场数据中国金属工艺品行业全景调研及投资可行性报告.docx
- 2026年及未来5年市场数据中国金属家具市场分析及投资战略研究预测可行性报告.docx
- 2026年及未来5年市场数据中国金属膜电阻器行业市场需求预测与投资战略规划分析报告.docx
- 2026年及未来5年市场数据中国金银花行业市场发展战略分析及投资前景专项预测报告.docx
- 2026年及未来5年市场数据中国金银花行业市场研究及投资战略预测报告.docx
- 2026年及未来5年市场数据中国抗氧化剂市场专项调查分析及投资前景预测报告.docx
- 2026年及未来5年市场数据中国救护车市场运行格局及投资战略研究报告.docx
- 2026年及未来5年市场数据中国精细化工行业发展前景预测及投资分析报告.docx
原创力文档

文档评论(0)