#include <iostream>using namespace std;class AbstractClass{protected: virtual void AbstractFunc() = 0;public: AbstractClass();};AbstractClass::AbstractClass(){ AbstractFunc();}int main(){ return 0;}
In constructor 'AbstractClass::AbstractClass()':warning: abstract virtual 'virtual void AbstractClass::AbstractFunc()' called from constructorundefined reference to `AbstractClass::AbstractFunc()'undefined reference to `AbstractClass::AbstractFunc()'collect2: ld returned 1 exit status
class AbstractClass{protected: virtual void AbstractFunc() { cout << "AbstractClass" << endl; }public: AbstractClass();};class RealClass: public AbstractClass{protected: void AbstractFunc() { cout << "RealClass\n" << endl; }};AbstractClass::AbstractClass(){ AbstractFunc();}int main(){ RealClass rc; return 0;}
C++ (Qt)#include <iostream> class Base{public: Base() { void *vtbl = reinterpret_cast<void**>( this )[ 0 ]; std::cout << "Constructor Base vtbl = " << vtbl << std::endl; method(); }; virtual void method() { void *vtbl = reinterpret_cast<void**>( this )[ 0 ]; std::cout << "Base::method vtbl = " << vtbl << std::endl; }}; class Derived : public Base{public: Derived() { void *vtbl = reinterpret_cast<void**>( this )[ 0 ]; std::cout << "Constructor Derived vtbl = " << vtbl << std::endl; }; virtual void method() { void *vtbl = reinterpret_cast<void**>( this )[ 0 ]; std::cout << "Derived::method vtbl = " << vtbl << std::endl; }}; int main(){ std::cout << "----- Build base -----" << std::endl; Base base; std::cout << "----- Build derived -----" << std::endl; Derived derived;}