我正在尝试创建一个允许可变数量输入的方法。我试图实现this回答(请参阅下面的代码)但是,当我尝试运行代码时出现错误。
头:
template<typename T, typename... Args>
void vSend ( T tIn, Args... AArgs );
template <typename T>
void vSend ( T tIn );
CPP
template<typename T, typename... Args>
void Connector::vSend ( T tIn, Args... AArgs )
{
pPacketToSend << tIn;
vSend(AArgs...);
}
template <typename T>
void Connector::vSend ( T tIn )
{
pPacketToSend << tIn;
tSocket.send(pPacketToSend);
}
Undefined symbols for architecture x86_64:
"void Connector::vSend<int, int>(int, int)", referenced from:
Updater::Update(sf::Image*) in updatedirector.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
结果模板只能在头文件中实现。