不久前,这个
question
被问到,关于熟悉的
error: 'static' can only be specified inside the class definition
错误。
在我当前的用例中,我将从一个非常MSVC的项目开始,在这个项目中,几乎所有的代码都是使用MSVC编译的,并且是针对Android的交叉编译。
我注意到没有MSVC错误,尤其是警告,关于静态类方法在类内部(外部)有定义。我错过什么了吗?为什么至少没有警告?
编辑
为了澄清这一点,我在问为什么没有适当的MSVC/MSV警告代码(摘自上面的链接):
class Foobar {
public:
static void do_something();
};
static void Foobar::do_something() {} // Error!
int main() {
Foobar::do_something();
}
编辑
真抱歉,伊芙妮!这个样品不行!我很抱歉。
class Foobar {
public:
template<class Y>
static int do_something();
};
template<class Y>
static int Foobar::do_something() {return 1;} // Error!
int main() {
return Foobar::do_something<double>();
}
这是输出
MSVC 19.14
(成功)
GCC 4.12
(失败)。