GCC: Undefined reference to vtable

Viewed 6165

This question differs from e.g.

What is the difference between g++ and gcc?

since if it is known that the cause of the described problem is "the difference between g++ and gcc", there's no need to look for an answer anymore. In other words, though the answer is the same, the question is different.

I have the following program test.cpp:

struct CircuitElement {
    bool value;
    const char *name;
    CircuitElement *next;

    CircuitElement (const char *name);    
    virtual void evaluate () = 0;       
};

struct Button: CircuitElement {
    Button (const char *name);
    virtual void evaluate ();
};

CircuitElement::CircuitElement (const char *name): name (name), next (0) {
}

Button::Button (const char *name): CircuitElement (name) {
}

void Button::evaluate () {
    // Some statements
}

Button button ("button");

int main () {
    return 0;
}

It compiles alright on www.cpp.sh, but if I compile it with locally with:

gcc test.cpp

I get the following errors:

C:\Users\info_000\AppData\Local\Temp\cceVLVFd.o:test.cpp:(.rdata$_ZTV14CircuitElement[_ZTV14CircuitElement]+0x10): undefined reference to `__cxa_pure_virtual'
C:\Users\info_000\AppData\Local\Temp\cceVLVFd.o:test.cpp:(.rdata$_ZTI6Button[_ZTI6Button]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
C:\Users\info_000\AppData\Local\Temp\cceVLVFd.o:test.cpp:(.rdata$_ZTI14CircuitElement[_ZTI14CircuitElement]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2.exe: error: ld returned 1 exit status

I must be doing wrong something trivial, and I've been Googling for an answer quite some time, but to no avail.

What am I missing?

0 Answers
Related