更新: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);
}