Linker error: wants C++ virtual base class destructor
- by jdmuys
Hi, I have a link error where the linker complains that my concrete class's destructor is calling its abstract superclass destructor, the code of which is missing.
This is using GCC 4.2 on Mac OS X from XCode.
I saw http://stackoverflow.com/questions/307352/g-undefined-reference-to-typeinfo but it's not quite the same thing.
Here is the linker error message:
Undefined symbols:
"ConnectionPool::~ConnectionPool()", referenced from:
AlwaysConnectedConnectionZPool::~AlwaysConnectedConnectionZPool()in RKConnector.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Here is the abstract base class declaration:
class ConnectionPool {
public:
static ConnectionPool* newPool(std::string h, short p, std::string u, std::string pw, std::string b);
virtual ~ConnectionPool() =0;
virtual int keepAlive() =0;
virtual int disconnect() =0;
virtual sql::Connection * getConnection(char *compression_scheme = NULL) =0;
virtual void releaseConnection(sql::Connection * theConnection) =0;
};
Here is the concrete class declaration:
class AlwaysConnectedConnectionZPool: public ConnectionPool {
protected:
<snip data members>
public:
AlwaysConnectedConnectionZPool(std::string h, short p, std::string u, std::string pw, std::string b);
virtual ~AlwaysConnectedConnectionZPool();
virtual int keepAlive(); // will make sure the connection doesn't time out. Call regularly
virtual int disconnect(); // disconnects/destroys all connections.
virtual sql::Connection * getConnection(char *compression_scheme = NULL);
virtual void releaseConnection(sql::Connection * theConnection);
};
Needless to say, all those members are implemented. Here is the destructor:
AlwaysConnectedConnectionZPool::~AlwaysConnectedConnectionZPool()
{
printf("AlwaysConnectedConnectionZPool destructor call"); // nothing to destruct in fact
}
and also maybe the factory routine:
ConnectionPool* ConnectionPool::newPool(std::string h, short p, std::string u, std::string pw, std::string b)
{
return new AlwaysConnectedConnectionZPool(h, p, u, pw, b);
}
I can fix this by artificially making my abstract base class concrete. But I'd rather do something better. Any idea?
Thanks