Add a non-inline non-virtual function to your class and add it's impl to the C++ file.
From vijayan121 response in this thread:
this is perhaps the most obscure error message that gcc (actually the linker) spits out, but the reason is simple:
the compiler has to put the (one and only one) vtable for a class into some object file or the other. it puts it into the object file for the translation unit where the definition of the first non-pure-virtual out-of-line virtual member function is present. if there is no such definition, you get this rather unhelpful linker error message.
you would be able to progressively compile the code even if a non-pure virtual function is not defined, but to be able to link without errors, every such function must have a definition (at least a stub). and to prevent the non-creation of a v-table by the compiler, at least one of the non-pure virtual functions will have to be defined out-of-line.
What do you mean by in-line and out-of-line functions? Do in-line functions have an implementation defined where they're declared (something like int getX() {return x;}) and out-of-line functions have an implementation defined in a separate file
1 2 3 4
int Math::add( int a, int b )
{
return a+b;
}
?
EDIT: I tried changing Block.h to
1 2 3 4 5 6
class Block
{
public:
Block();
virtualvoid display() {};
};
but I got the same results, so apparently that isn't it.
class Block
{
public:
Block();
int add( int, int );
int five() {return 5;};
virtualvoid display() = 0;
};
and added an implimentation of add, like so:
1 2 3 4
int Block::add( int a, int b )
{
return a+b
}
and now there's no linker errors. Lemme just see if I can make this work with the full project...
Nope. I added the add() and five() functions to the real Block.h, but to no avail. I then tried deleting usingnamespace std; and now it links! I tried running the exe it created to test it out, but the thing told me that "The application has requested Runtime to terminate it in an unusual way", so IDK what that's about... probably some conflicts in my code. I'll mess around with it and report back.