Mail Archives: djgpp/1997/06/13/00:25:14
Mike Orbinpost wrote:
>
> I am getting an Undefined symbol error when I build this project (in the
> linking actually). outFile is defined as a virtual function in both the
> base and derived classes, it is implemented in the derived class but
> used
> in a friend function of the base. From what I have read (in C++ Primer
> Plus by Waite Group Press) this should be a legitimate practice.
> Anybody
> have any ideas.
The linker errors I get are:
/tmp/cca185292.o: In function `person::~person(void)':
/tmp/cca185292.o(.text+0xb8): undefined reference to
`Collectable::~Collectable(void)'
/tmp/cca185293.o: In function `person::person(char *)':
/tmp/cca185293.o(.text+0xd): undefined reference to
`Collectable::Collectable(void)'
/tmp/cca185293.o: In function `person::~person(void)':
/tmp/cca185293.o(.text+0x12c): undefined reference to
`Collectable::~Collectable(void)'
These are legitimate errors. It's saying that it can't find
Collectable::Collectable and Collectable::~Collectable, which is correct,
because you haven't defined them.
If you're going to have a base class that will never be created itself,
then you should make it an abstract class. You can make it abstract by
making any (but not necessarily all) of the virtual members pure, that is
by appending = 0 on the prototype. Change the definition of Collectables
in testbase.h to this and it will work:
class Collectable
{
public:
Collectable() { } // this line can be left out
virtual ~Collectable() { }
virtual void outStream( ostream & os ) const = 0; // pure virtual
friend ostream & operator<<(ostream & os, const Collectable & C );
};
--
Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
Alcyone Systems / web / http://www.alcyone.com/max/
San Jose, California, United States / icbm / 37 20 07 N 121 53 38 W
\
"Covenants without the sword / are but words."
/ Camden
- Raw text -