“static”不应在文件范围内定义的成员函数上使用

C++编译提示““static”不应在文件范围内定义的成员函数上使用”这个错误,问题发生在实现体上也加了static,如下错误示例:

.h文件

class MyClass {
public:
    static void my_static_method();
};


.cpp文件

static void MyClass::my_static_method(){   //这里的static编译提示错误   
   //do something
}

解决方法:在实现体上去掉“static”, 只需要在声明的地方加上。正确的示例如下:

.h文件

class MyClass {
public:
    static void my_static_method();
};


.cpp文件

void MyClass::my_static_method(){ 
   //do something
}

你可能感兴趣的:(c++,windows)