具有模板方法的非模板类的静态成员

时间:2012-08-30 15:16:52

标签: templates static-members

我有以下类结构:

class A {
  template<typename T> static void f(const T& input) {
     //do something with X and input
  }
  static ostringstream x;
}

然后在主要的我做:

...
int n = 5;
A::f(n);
...

这编译很好,但我得到一个链接错误,A :: x是一个无法找到的符号。有没有人遇到过这个错误?

谢谢!

2 个答案:

答案 0 :(得分:2)

是的,您还没有定义x

// A.cpp
std::ostringstream A::x;

答案 1 :(得分:0)

改为使用A::f<int>(n);

相关问题