How to get the address of an overloaded member function?

你说的曾经没有我的故事 提交于 2019-11-28 09:46:21

Well, i'll answer what i put as comment already so it can be accepted. Problem is with constness:

class C
{
  bool f(int) { ... }
  bool f(double) const { ... }

  bool example()
  {
    // I want to get the "double" version.
    typedef bool (C::*MemberFunctionType)(double) const; // const required!
    MemberFunctionType pointer = &C::f;
  }
};

Clarification:

The original question didn't contain that const. I did a wild guess in the comments whether he possibly has f being a const member function in the real code (because at a yet earlier iteration, it turned out yet another thing was missing/different to the real-world code :p). He actually had it being a const member function, and told me i should post this as an answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!