编译问题,类之间相互引用。
windows 下没问题,Linux 下一直没解决啊!
程序框架如下:
/**
* 文件名: MessageFactory.h
**/
#ifndef MessageFactory_h
#define MessageFactory_h
#include "MessageServer.h "
class MessageServer ;
class MessageFactory
{
public:
MessageFactory(void){}
virtual ~MessageFactory(void){}
virtual void CreateReceiver(int code, MessageServer* server) = 0;
};
#endif
/**
* 文件名: MessageFactoryImpl.h
**/
#ifndef MessageFactoryImpl_h
#define MessageFactoryImpl_h
#include "MessageFactory.h "
class MessageFactoryImpl :public MessageFactory
{
public:
MessageFactoryImpl();
virtual ~MessageFactoryImpl(){}
virtual void CreateReceiver(int code, MessageServer* server);
};
#endif
/**
* 文件名: MessageFactoryImpl.cpp
**/
#include "MessageFactoryImpl.h "
MessageFactoryImpl::MessageFactoryImpl()
{
}
void MessageFactoryImpl::CreateReceiver(int code, MessageServer* server)
{
}
/**
* 文件名: MessageServer.h
**/
#ifndef MessageServer_h
#define MessageServer_h
#include "MessageFactory.h "
class MessageFactory ;
class MessageServer
{
public:
MessageServer();
MessageServer(int udpPort, MessageFactory* factory, long timeout);
virtual ~MessageServer();
};
#endif
/**
* 文件名: MessageServer.cpp
**/
#include "MessageServer.h "
MessageServer::MessageServer()
{
}
MessageServer::MessageServer(int udpPort, MessageFactory* factory, long timeout)
{
}
MessageServer::~MessageServer()
{
}
//:test.cpp
#include <iostream>
#include "MessageFactoryImpl.h "
#include "MessageServer.h "
using namespace std;
int main()
{
MessageFactoryImpl *a=new MessageFactoryImpl();
MessageServer *b=new MessageServer();
cout < < "it 's ok " < <endl;
delete a;
delete b;
return 0;
}
# makefile
test: MessageFactoryImpl.o MessageServer.o
g++ test.cpp -o test
MessageFactoryImpl.o: MessageFactoryImpl.h MessageFactory.h \
MessageServer.o
g++ -c MessageFactoryImpl.cpp
MessageServer.o: MessageFactory.h MessageServer.h
g++ -c MessageServer.cpp
------解决方案--------------