undefined reference to `vtable for

I got this error when I compile a class:
undefined reference to `vtable for Device’

it turns out that GCC requires every virtual function to be defined, so I need to add an inline {} just to satisfy this.

virtual void setGridSpc(double a){};

instead of

virtual void setGridSpc(double a);

Advertisements

2 Responses

  1. Look up “pure virtual function” in your favorite C++ text book.

  2. In case you don’t know what I was talking about: Prefer to make base classes (you derive publicly from) abstract. You can create abstract classes by declaring pure virtual functions. Such an abstract class should also have a destructor that is either public and virtual or protected and non-virtual. Example:

    class foo {
    public:
    virtual ~foo() {}
    virtual void setGridSpc(double a) = 0;
    };

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: