is the undefined reference to vtable error solved by modern g++ compilers?

c++, g++, gcc, virtual-functions

Solution

You didn't read the documentation properly. The first sentence in the relevant paragraph says:

The ISO C++ Standard specifies that all virtual methods of a class that are not pure-virtual must be defined, but does not require any diagnostic for violations of this rule [class.virtual]/8.

So, it is expected that you may not get an error, especially since you are not actually invoking `test()` (despite the lie in the constructor's output).

Speaking practically, you are likely to get this diagnostic only under the following circumstances:

- you call a virtual function that you did not define

- you instantiate an object whose `virtual` destructor you did not define

But make no mistake: your program has undefined behaviour regardless.

Problem

according to this virtual functions must be defined otherwise linker complains & reports error "undefined reference to vtable", but why doesn't ideone compiler give any errors for the following code? ``` #include <iostream> using namespace std; class Test { public: Test() { cout<<"test() is called\n"; } virtual void test(); }; int main() { Test t; // your code goes here return 0; } ```

Original source

Related problems