I've a set of possible connections in my SW so I decided to use the Factory Pattern, so I created the base class (both .h and .cpp)
The following the content of Connection.h
header file
namespace Connection
{
class Connection
{
public:
Connection();
~Connection();
virtual void sendPacket(Packet* p) = 0;
virtual void receivePacket() = 0;
virtual int connect() = 0;
virtual void disconnect() = 0;
}
}
Even a Connection.cpp file exists but it has only an empty constructor and deconstructor.
Next, I created the derivated class (both .h and .cpp files)
namespace Connection
{
class SocketConnection : public Connection
{
public:
SocketConnection();
~SocketConnection();
}
}
and its relative SocketConnection.cpp file where I'm trying to define the pure virtual methods defined in Connection.h
namespace Connection
{
SocketConnection::SocketConnection() { }
SocketConnection::~SocketConnection() { }
int connect()
{
//Design of socket connection
}
}
Next, I created a new Connection, DatabaseConnection defined pratically in the same way of the SocketConnection().
The error I get is
multiple definition of Connection::connect();
while invoking the Cross G++ Linker
but I can't find out the reason. Can anyone tell me where I'm wrong? Thank you!