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.
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 {}
};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
What Is a Lambda Expression in C++11
Start Thread With Member Function
Is Segmentation Fault Actual Undefined Behavior When We Refer to a Non-Static Data-Member
C++ Unordered_Map Using a Custom Class Type as the Key
Raii and Smart Pointers in C++
How to Get Assembler Output from C/C++ Source in Gcc
Detecting Endianness Programmatically in a C++ Program
How to Find Out If an Item Is Present in a Std::Vector
Initialization of All Elements of an Array to One Default Value in C++
Where Do I Find the Current C or C++ Standard Documents
How Does the Compilation/Linking Process Work
Difference Between 'Struct' and 'Typedef Struct' in C++
Why Do Function Pointer Definitions Work With Any Number of Ampersands '&' or Asterisks '*'
Implicit Type Conversion Rules in C++ Operators
Is Local Static Variable Initialization Thread-Safe in C++11