参考:

1.http://www.tianya.cn/publicforum/content/it/1/256804.shtml

2.http://bbs.bccn.net/thread-47699-1-1.html

 

类中的成员函数指针的声明与使用方法,注:编译通过,但不知运行结果。



摘录:

构造一个指向成员的指针需要显式使用地址运算符&和限定名。
从类的外部访问该类的成员需要范围解析运算符 (::) 和地址运算符&。生成下面的示例 C2475:
  // C2475.cpp
  #include <stdio.h>
  
  struct A {
   void f() {
   printf("test");
   }
   void g();
  };
  
  void A::g() {
   void (A::*p1)() = f; // ok in -Ze; error in -Za (C2475)
   void (A::*p5)() = this->f; // C2475
  
   // the following line shows how to call a function from outside the class
   // void (A::*p4)() = &A::f;
  }
  
  int main() {
   A *ap = new A;
   A a;
   void (A::*p5)() = a.f; // C2475
  
   // the following line shows how to call a function from outside the class
   void (A::*p4)() = &A::f;
  
   // the following line shows how to call a member function
   (ap->*p4)();
   return 0;
  }

Logo

昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链

更多推荐