C++ 虚函数virtual

来源:互联网 发布:js 滑动特效 编辑:程序博客网 时间:2024/05/16 07:01

The purpose of the virtual keyword is to enable dynamic binding. By default, member functions are nonvirtual. Calls to nonvirtual functions are resolved at compile time. To specify that a function is virtual, we precede its return type by the keyword virtual . Any nonstatic member function, other a constructor, may be virtual. The virtual keyword appears only on the member-function declaration inside the class. The virtual keyword may not be used on a function definition that appears outside the class body.


Best Practices: A base class usually should define as virtual any function that a derived class will need to redefine.

0 0
原创粉丝点击