首页 > 编程语言 > 详细

usage and explanation of c++ virtual keyword virtual 用法和解释

时间:2017-10-15 18:31:34      阅读:237      评论:0      收藏:0      [点我收藏+]

virtual is the keyword of defination c++ virtual function
concept:
(1)inheritance as a prerequisite
(2)decorate the function with virtual keyword in the parent class
(3)rewrite thr virtual function in the subclass
effect:
(1)a reference to a parent is used as a parameter type for a function
(2)call the function to pass the subclass object
(3)can call the rewritten virtual function in subclass by the parent class reference

概念:
(1)以继承为前提。
(2)在父类中用virtual修饰函数。
(3)在子类中重写该虚函数。
作用:
(1)以父类的引用作为函数的参数类型。
(2)调用该函数传递子类对象。
(3)在函数中可以通过该父类的引用调用到子类中重写的虚函数。

usage and explanation of c++ virtual keyword virtual 用法和解释

原文:http://www.cnblogs.com/1915884031A-qqcom/p/7672768.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!