我似乎做错了什么,但我不确定是什么。这是我正在尝试做的最小示例:
#include <iostream>
using std::cout;
class CallMe {
public:
void Maybe() {
cout << "A";
}
};
class TemplateValue {
public:
static CallMe call_me;
};
template<typename T>
void CallMemberMember() {
T::call_me.Maybe();
}
int main(int argc, char *argv[]) {
CallMemberMember<TemplateValue>();
}
当我尝试构建它时,我收到一个链接错误:
$ clang++ --std=c++11 repro_link_error.cc
Undefined symbols for architecture x86_64:
"TemplateValue::call_me", referenced from:
void CallMemberMember<TemplateValue>() in repro_link_error-9BE9gw.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我究竟做错了什么?