Z
ZikO
Hi
What's wrong with this code? Why can't I compile this?
I have created a virtual destructor in one of my code in a base class to
be sure objects of all derived classes would be destroyed. However, the
compiler says "no" with this comments:
C:\DOCUME~1\User\LOCALS~1\Temp/ccLAUiQR.o:test2.cpp.text$_ZN1BD2Ev[B::~B()]+0x17):
undefined reference to `A::~A()'
C:\DOCUME~1\User\LOCALS~1\Temp/ccLAUiQR.o:test2.cpp.text$_ZN1BD0Ev[B::~B()]+0x17):
undefined reference to `A::~A()'
C:\DOCUME~1\User\LOCALS~1\Temp/ccLAUiQR.o:test2.cpp.text$_ZN1BD1Ev[B::~B()]+0x17):
undefined reference to `A::~A()'
collect2: ld returned 1 exit status
This is a simple code which roughly represents the problem:
// code
#include <iostream>
using namespace std;
class A {
public:
virtual ~A() = 0;
};
class B : public A {};
class C : public B {};
class D : public C {};
int main(int argc, char *argv[])
{
D d;
A &a = d;
return 0;
}
// end of code
Without lines in main everything compiles successfully.
Best
What's wrong with this code? Why can't I compile this?
I have created a virtual destructor in one of my code in a base class to
be sure objects of all derived classes would be destroyed. However, the
compiler says "no" with this comments:
C:\DOCUME~1\User\LOCALS~1\Temp/ccLAUiQR.o:test2.cpp.text$_ZN1BD2Ev[B::~B()]+0x17):
undefined reference to `A::~A()'
C:\DOCUME~1\User\LOCALS~1\Temp/ccLAUiQR.o:test2.cpp.text$_ZN1BD0Ev[B::~B()]+0x17):
undefined reference to `A::~A()'
C:\DOCUME~1\User\LOCALS~1\Temp/ccLAUiQR.o:test2.cpp.text$_ZN1BD1Ev[B::~B()]+0x17):
undefined reference to `A::~A()'
collect2: ld returned 1 exit status
This is a simple code which roughly represents the problem:
// code
#include <iostream>
using namespace std;
class A {
public:
virtual ~A() = 0;
};
class B : public A {};
class C : public B {};
class D : public C {};
int main(int argc, char *argv[])
{
D d;
A &a = d;
return 0;
}
// end of code
Without lines in main everything compiles successfully.
Best