好吧,我一直把我们的游戏引擎移植到iOS上,并遇到了一个奇怪的问题。 我们的引擎定义了专门用于char和wchar_t的模板化String类。该类具有静态“s_empty”属性:
// MyString.h
namespace MyEngine
{
template <typename T> class String
{
...
static const String s_empty;
};
...
}
//MyString.cpp
namespace MyEngine
{
template <> String<char> const String<char>::s_empty;
template <> String<wchar_t> const String<wchar_t>::s_empty;
// Yes, compiler forces me to start with "template <>"
...
}
该项目的另一个模块使用此变量:
const MyEngine::String<wchar_t> &f()
{
return MyEngine::String<wchar_t>::s_empty;
}
这些东西在不同的平台和各种编译器上已经很好地工作了很长时间:MSVC + PC86,Codewarrior + NDS和Wii。它适用于设备上的iOS,但不适用于模拟器! 在模拟器上,链接器会生成错误:
架构i386的未定义符号: “MyEngine ::字符串&LT; wchar_t的&GT; :: s_empty”
帮助! )
P.S。 “Compile Sources As”设置为“Objective-C ++”。