【发布时间】:2012-01-27 12:53:29
【问题描述】:
我有一个模板类,它只有静态函数和字段。
template<typename T> class Luaproxy {
static std::map<std::string, fieldproxy> fields;
static const char * const CLASS_NAME;
static void addfields();
static int __newindex(lua_State * l){
//implemented stuff, references to fields...
}
//etc
}
如你所见,有些函数只是声明的,因为我打算用模板特化来实现它们。
在 .ccp 文件中我有:
struct test { int a; }
template<> map<string, fieldproxy> Luaproxy<test>::fields;
template<> const char * const Luaproxy<test>::CLASS_NAME=typeid(test).name();
template<> void Luaproxy<test>::addfields(){
//stuff, references to fields...
}
我从在标头中实现的函数和仅在 .cpp 中专用的函数中都得到了对 Luaproxy<test>::fields 的未定义引用错误。请注意,Luaproxy<test>::CLASS_NAME 和 Luaproxy<test>::addfields 似乎在链接中。
是什么让map 如此特别?
【问题讨论】:
-
制作“模板类 Luaproxy;” cpp 文件顶部的条目。我认为必须解决它
标签: c++ templates static linker