码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-10-15 19:51:19      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:object   概念   virt   对象   written   rtu   key   用法   can   

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 用法和解释

标签:object   概念   virt   对象   written   rtu   key   用法   can   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!