What does the standard say about this

Discussion in 'C++' started by Xenos, Jul 10, 2004.

  1. Xenos

    Xenos Guest

    I just spend about an hour tracking down a link error with GCC. I had
    defined a virtual member function, but never referenced it. With this
    declaration, the linker would complain that the virtual table for the class
    was missing. I know that it is acceptable by the standard to declare a
    non-virtual member but not define it, if it is never accessed. Is the same
    true for virtual members?


    Xenos, Jul 10, 2004
    1. Advertisements

  2. Xenos wrote in in
    No, but you can declare the member pure-virtual, in which case
    (as long as it isn't the destructor) you don't need a defenition.

    However it makes the class *abstract*, i.e. you may not create
    instances of it (even if you do provide a defenition).

    struct X
    virtual int f() = 0; /* = 0 means: pure */

    struct Y : X
    virtual int f();

    int Y::f()
    return 0;

    int main()
    Y y;
    return y.f();

    Rob Williscroft, Jul 10, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.