C++ pure virtual function have body [duplicate]

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, non-virtually, directly (without virtual dispatch). In C++ language a non-virtual call … Read more

What is the purpose of __cxa_pure_virtual?

If anywhere in the runtime of your program an object is created with a virtual function pointer not filled in, and when the corresponding function is called, you will be calling a ‘pure virtual function’. The handler you describe should be defined in the default libraries that come with your development environment. If you happen … Read more

Pure virtual functions may not have an inline definition. Why?

In the SO thread “Why is a pure virtual function initialized by 0?” Jerry Coffin provided this quote from Bjarne Stroustrup’s The Design & Evolution of C++, section §13.2.3, where I’ve added some emphasis of the part I think is relevant: The curious =0 syntax was chosen over the obvious alternative of introducing a new … Read more

Difference between a virtual function and a pure virtual function [duplicate]

A virtual function makes its class a polymorphic base class. Derived classes can override virtual functions. Virtual functions called through base class pointers/references will be resolved at run-time. That is, the dynamic type of the object is used instead of its static type: Derived d; Base& rb = d; // if Base::f() is virtual and … Read more

Where do “pure virtual function call” crashes come from?

They can result if you try to make a virtual function call from a constructor or destructor. Since you can’t make a virtual function call from a constructor or destructor (the derived class object hasn’t been constructed or has already been destroyed), it calls the base class version, which in the case of a pure … Read more

call to pure virtual function from base class constructor

There are many articles that explain why you should never call virtual functions in constructor and destructor in C++. Take a look here and here for details what happens behind the scene during such calls. In short, objects are constructed from the base up to the derived. So when you try to call a virtual … Read more

Undefined symbols “vtable for …” and “typeinfo for…”?

If Obstacle is an abstract base class, then make sure you declare all its virtual methods “pure virtual”: virtual void Method() = 0; The = 0 tells the compiler that this method must be overridden by a derived class, and might not have its own implementation. If the class contains any non-pure virtual functions, then … Read more