共用方式為


編譯器錯誤 C3867

更新:2007 年 11 月

錯誤訊息

'func': 函式呼叫遺漏引數清單,請用 '&func' 建立成員的指標

您嘗試使用成員函式的位址,而並未以其類別名稱和傳址運算子限定成員函式。

對 Visual C++ 2005 的編譯器完成一致性處理後也可能會產生這項錯誤:增強型成員指標一致性。在 Visual C++ 2005 之前編譯的程式碼現在會產生 C3867 錯誤。如需詳細資訊,請參閱 Visual C++ 2005 編譯器的重大變更

範例

在 Visual C++ 2005 中,從編譯器發出 C3867 時,可能會附帶容易讓人誤導的建議解決方案。請盡可能地使用最具衍生性的類別。

下列範例會產生 C3867。

// C3867_1.cpp
// compile with: /c
struct Base { 
protected: 
   void Test() {}
};

class Derived : public Base { 
   virtual void Bar();
};

void Derived::Bar() {
   void (Base::*p1)() = Test;   // C3867
   &Derived::Test;   // OK
}

下列範例會產生 C3867。

// C3867_2.cpp
#include<stdio.h>

struct S {
   char *func() {
      return "message";
   }
};

class X {
public:
   void f() {}
};

int main() {
   X::f;   // C3867

   // OK
   X * myX = new X;
   myX->f();

   S s;
   printf_s("test %s", s.func);   // C3867
   printf_s("test %s", s.func());   // OK
}

下列範例會產生 C3867。

// C3867_3.cpp
class X {
public:
   void mf(){}
};
 
int main() {
   void (X::*pmf)() = X::mf;   // C3867

   // try the following line instead
   void (X::*pmf2)() = &X::mf;
}

下列範例會產生 C3867。

// C3867_4.cpp
// compile with: /c
class A {
public:
   void f(int) {}

   typedef void (A::*TAmtd)(int);

   struct B {
      TAmtd p;
   };

   void g() {
      B b1;
      b1.p = f;   // C3867
   }
};

下列範例會產生 C3867。

// C3867_5.cpp
// compile with: /EHsc
#include <iostream>

class Testpm {
public:
   void m_func1() {
      std::cout << m_num << "\tm_func1\n"; 
    }

   int m_num;
   typedef void (Testpm::*pmfn1)();
   void func(Testpm* p);
};

void Testpm::func(Testpm* p) {
   pmfn1 s = m_func1;   // C3867
   pmfn1 s2 = &Testpm::m_func1;   // OK
   (p->*s2)();
}

int main() {
   Testpm *pTestpm = new Testpm;
   pTestpm->m_num = 10;
 
   pTestpm->func(pTestpm);
}