我有一个仅供本地使用的类(即,它的对应只是它定义的 c++ 文件)
class A {
public:
static const int MY_CONST = 5;
};
void fun( int b ) {
int j = A::MY_CONST; // no problem
int k = std::min<int>( A::MY_CONST, b ); // link error:
// undefined reference to `A::MY_CONST`
}
所有代码都驻留在同一个 c++文件中。在windows上使用VS编译时,完全没有问题。
但是,在 Linux 上编译时,我undefined reference
只收到第二条语句的错误。
有什么建议么?