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

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)在函数中可以通过该父类的引用调用到子类中重写的虚函数。

posted @ 2017-10-15 17:15  diamondDemand  阅读(134)  评论(0编辑  收藏  举报