How to print member function address in C++

前端 未结 4 1569
星月不相逢
星月不相逢 2020-12-01 09:40

It looks like std::cout can\'t print member function\'s address, for example:

#include 

using std::cout;
using std::endl;

clas         


        
4条回答
  •  無奈伤痛
    2020-12-01 10:28

    One way to do that is (I'm not sure it's portable) :

    void TestClass::PrintMyFuncAddress(void)
    {
      void (TestClass::* ptrtofn)() = &TestClass::MyFunc;
      cout << (void*&)ptrtofn<< endl;
    }
    

    working example : http://ideone.com/1SmjW

提交回复
热议问题