本文共 815 字,大约阅读时间需要 2 分钟。
轉載自
Your assumption that pure virtual function cannot be called is absolutely incorrect. When a function is declared pure virtual, it simply means that this function cannot get called dynamically, through a virtual dispatch mechanism. Yet, this very same function can easily be called statically, without virtual dispatch.
In C++ language static call to a virtual function is performed when a qualified name of the function is used in the call, i.e. when the function name specified in the call has the <class name>::<function name>
form.
For example
struct S { virtual void foo() = 0; }; void S::foo() { // body for the pure virtual function `S::foo` } struct D : S { void foo() { S::foo(); // static call to `S::foo` from derived class } }; int main() { D d; d.S::foo(); // another static call to `S::foo` }
转载地址:http://oesgi.baihongyu.com/