Undefined Reference to Vtable

Undefined reference to vtable

So, I've figured out the issue and it was a combination of bad logic and not being totally familiar with the automake/autotools world. I was adding the correct files to my Makefile.am template, but I wasn't sure which step in our build process actually created the makefile itself. So, I was compiling with an old makefile that had no idea about my new files whatsoever.

Thanks for the responses and the link to the GCC FAQ. I will be sure to read that to avoid this problem occurring for a real reason.

Undefined reference to `vtable' in the constructor [duplicate]

What aschepler said is absolutely correct. Concerned about your begining, you may want some advice when a virtual function should be used though. Vitual function is used as a method to support polymorphism in cpp, and can be divided into two using scenario.

  1. Interface/ abstract class

    In this scenario, virtual function was declared as pure virtual, with which one class would be called as abstract class and non-instancable. By doing this, you can implement 'interface' like most modern programming support.

    class Interface {
    //....
    virtual void f() = 0;
    };
    class Concrete: public Interface {
    // override this f()
    void f() override {}
    };
  2. Polymorphism/ concrete class

    In this scenario, virtual function was declared as normal function except it can be override by derived class. And you must implement it.

    class Parent {
    //...
    virtual void g();
    }
    class Derived: public Parent {
    //...
    void g() override{}
    }

Note that you can still declare a function with the same name of parent, which was not declared as virtual function. This would be called hide, and is another topic.

Undefined reference to vtable

You need to either make virtual void move(); a pure virtual function:

virtual void move() = 0;

or define Actor::move() for a base class

void Actor::move() 
{
// do something
}

Undefined reference to `vtable

You need to define the dtor as well, which will create the vtable

CustomMenuFilter::~CustomMenuFilter() { ... }

While there are some (compiler-dependent) rules that describe when exactly the compiler emits a vtable, it's usually not important for you to know. The important thing is, that you need to define the dtor and the compiler will take care of the vtable then, so if you see the error "undefined reference to vtable", always check the dtor.

undefined reference to vtable when calling constructor of base class

This is most likely to mean that you forgot to implement one of the virtual functions declared in CProcManager - probably GetMemLimit. Or that you forgot to link with the translation unit containing that implementation.

Explanation: it looks like you're compiling with GCC. That compiler generates the vtable in the same translation unit as the first non-inline, non-pure virtual function declared in the class. If you don't implement that function, the vtable will be missing, giving that error.

Undefined Reference to vtable After Adding Destructor

You didn't define the member functions isString::getBuffer and isString::size. You need to define them.

If you don't want the class to have definitions for these functions, you must mark them as pure virtual, making isString an abstract base class which cannot be instantiated directly:

virtual const char* getBuffer() const = 0;
virtual size_t size() const = 0;


Related Topics



Leave a reply



Submit