Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Undefined symbols: vtable for Foo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Undefined symbols: vtable for Foo



You must implement the first virtual method of a class because that's when the compiler actually generates the vtable for it.

In your example below, you should either make the method bar() in the Foo class a pure (abstract) virtual method, or you should explicitly declare and define an empty virtual destructor for Foo before the declaration of bar().

-John


On Saturday, August 2, 2003, at 03:42 PM, Randy Strauss wrote:

I compile the program below on Max OSX with
GCC version 1151, based on gcc version 3.1 20020420

g++ foo.cpp
ld: Undefined symbols: <-- ERROR
vtable for Foo

Any idea why?
Yes, Foo needs a vtable. Why isn't one created for it?
What must I do to get it created?
-r
**************** contents of foo.cpp **********

class Foo {

protected:
void setit(int);

public:
virtual void bar(); // only a subclass implements
};


class Bird : public Foo {

public:
void bar();
};

// ################

int a;

void Foo::setit(int i) {
a = i;
}

void Bird::bar() {
Foo::setit(8);
}

int main(int argc, char **argv) {
Bird *b = new Bird();
b->bar();
}

// end
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.