Error compiling with GCC
Pavel Rosenboim
pavelr at coresma.com
Mon Dec 15 08:31:53 UTC 2003
André Felício wrote:
> Hi,
>
> I am trying to compile a simple program in C++ and I am not obtaining. This
> returning the following error:
>
> [andre at antigerme poli]$ g++ test.cpp
> /tmp/ccwB8kUB.o(.text+0x18): In function `main':
> : undefined reference to `B::B[in-charge]()'
> /tmp/ccwB8kUB.o(.text+0x2d): In function `main':
> : undefined reference to `B::~B [in-charge]()'
> collect2: ld returned 1 exit status
> [andre at antigerme poli]$
>
> Basically I am trying you work with polimorf in the GCC.
>
> The simple program is:
>
> class A {
> public:
> A();
> ~A();
> };
>
> class B: public A {
> public:
> B();
> ~B();
> };
>
> int main(void) {
> A *a;
> B b;
> a = new B();
> }
You only declared constructors and destructors for the classes, but did
not define them. You could write A() {}; ~A() {}; instead to define
empty constructor and destructor.
HTH,
Pavel.
More information about the fedora-list
mailing list