我剛剛構建了我的助推網絡的模板實現。無法解析的外部符號與VS2010上的模板實現
這裏是我是誰喊我的網絡類模板類:
AbstractNetwork.hpp :
#include "Network.hpp"
template <typename T, typename R, typename S, typename A>
class AbstractNetwork
{
private:
T connection;
public:
AbstractNetwork(A acceptor)
{
connection = T::create(acceptor);
}
void write(const R msg)
{
connection->Swrite(msg);
}
R read(void)
{
connection->Sread();
return (connection->getIdata());
}
S getSocket(void)
{
return (connection->getSocket());
}
void close(void)
{
connection->close();
}
};
,這是我的網絡類誰正在與boost::tcp::socket
:
Network.hpp
class Network : public boost::enable_shared_from_this<Network>
{
private:
tcp::socket socket;
std::vector<char> Idata;
char Iheader[MYINT];
bool readHeader;
void endRead(const error_code& error, size_t nbytes);
void endWrite(const error_code &error);
size_t Isize;
public:
typedef boost::shared_ptr<Network> ptr;
Network(io_service &);
~Network();
void close(void);
void Sread(void);
void Swrite(Commande *);
tcp::socket& getSocket(void);
Commande* getIdata(void);
std::string convertHeader(void);
static ptr create(io_service &);
};
我不給所有的函數的代碼,因爲它太長,我敢肯定它的工作原理。
當我建立這個項目我已經在VS2010最終此以下錯誤:
error LNK2001: unresolved external symbol "public: void __thiscall AbstractNetwork<class boost::shared_ptr<class Network>,struct Commande *,class boost::asio::basic_stream_socket<class boost::asio::ip::tcp,class boost::asio::stream_socket_service<class boost::asio::ip::tcp> > &,class boost::asio::io_service &>::close(void)"
error LNK2001: unresolved external symbol "public: void __thiscall AbstractNetwork<class boost::shared_ptr<class Network>,struct Commande *,class boost::asio::basic_stream_socket<class boost::asio::ip::tcp,class boost::asio::stream_socket_service<class boost::asio::ip::tcp> > &,class boost::asio::io_service &>::write(struct Commande * const)"
error LNK2001: unresolved external symbol "public: class boost::asio::basic_stream_socket<class boost::asio::ip::tcp,class boost::asio::stream_socket_service<class boost::asio::ip::tcp> > & __thiscall AbstractNetwork<class boost::shared_ptr<class Network>,struct Commande *,class boost::asio::basic_stream_socket<class boost::asio::ip::tcp,class boost::asio::stream_socket_service<classboost::asio::ip::tcp> > &,class boost::asio::io_service &>::getSocket(void)"
error LNK2001: unresolved external symbol "public: __thiscall AbstractNetwork<class boost::shared_ptr<class Network>,struct Commande *,class boost::asio::basic_stream_socket<class boost::asio::ip::tcp,class boost::asio::stream_socket_service<class boost::asio::ip::tcp> > &,class boost::asio::io_service &>::AbstractNetwork<class boost::shared_ptr<class Network>,struct Commande *,classboost::asio::basic_stream_socket<class boost::asio::ip::tcp,class boost::asio::stream_socket_service<class boost::asio::ip::tcp> > &,class boost::asio::io_service &>(class boost::asio::io_service &)
它的長,但我想給你所有的這些錯誤,因爲我認爲這個問題來到我的模板類型。所以我認爲我的問題來到AbstractNetwork.hpp,但我找不到這個。
你有什麼想法嗎?
您是否使用方法的實現編寫了Network.cpp源代碼文件?你有沒有把它添加到你的項目?鏈接器錯誤說你沒有。 –
是啊是的,我有一個Network.cpp在我的projet,(我沒有給它,因爲它太長了),我敢肯定他是我的項目,因爲我編寫和測試之前添加我的AbstractNetwork –