编译器错误 C2663

“function”:数字重载对“this”指针没有合法转换

编译器无法将 this 转换为成员函数的任何重载版本。

此错误可能是由调用 const 对象上的非 const 成员函数造成的。 可能的解决方法:

  1. 从对象声明中删除 const

  2. const 添加到成员函数重载之一。

以下示例生成 C2663:

// C2663.cpp
struct C {
   void f() volatile {}
   void f() {}
};

struct D {
   void f() volatile;
   void f() const {}
};

const C *pcc;
const D *pcd;

int main() {
   pcc->f();    // C2663
   pcd->f();    // OK
}