共用方式為


編譯器錯誤 C2276

'operator': 系結成員函式運算式上的非法作業

編譯程式發現用來建立指針對成員的語法有問題。

備註

當您嘗試使用實例變數來限定成員,而不是類別類型時,通常會造成錯誤 C2276 。 如果您嘗試使用錯誤的語法來呼叫成員函式,也可能會看到此錯誤。

範例

此範例顯示 C2276 可能發生的幾種方式,以及如何修正它們:

// C2276.cpp
class A {
public:
   int func(){return 0;}
} a;

int (*pf)() = &a.func;   // C2276
// pf isn't qualified by the class type, and it 
// tries to take a member address from an instance of A.
// Try the following line instead:
// int (A::*pf)() = &A::func;

class B : public A {
public:
   void mf() {
      auto x = &this -> func;   // C2276
      // try the following line instead
      // auto x = &B::func;
   }
};

int main() {
   A a3;
   auto pmf1 = &a3.func;   // C2276
   // try the following line instead
   // auto pmf1 = &A::func;
}