Share via


编译器错误 C2352

“class::function”:非静态成员函数的非法调用

static 成员函数调用了非静态成员函数。 或者,从类外部将非静态成员函数作为静态函数进行了调用。

下面的示例生成 C2352,并演示如何修复此错误:

// C2352.cpp
// compile with: /c
class CMyClass {
public:
   static void func1();
   void func2();
   static void func3() {
      func2();   // C2352 calls nonstatic func2
      func1();   // OK calls static func1
   }
};

下面的示例生成 C2352,并演示如何修复此错误:

// C2352b.cpp
class MyClass {
public:
   void MyFunc() {}
   static void MyFunc2() {}
};

int main() {
   MyClass::MyFunc();   // C2352
   MyClass::MyFunc2();   // OK
}