Pointers to virtual member functions. How does it work?

前端 未结 3 881
無奈伤痛
無奈伤痛 2020-12-03 07:12

Consider the following C++ code:

class A
{
public:
      virtual void f()=0;
};


int main()
{
     void (A::*f)()=&A::f;
}

If I\'d hav

3条回答
  •  春和景丽
    2020-12-03 07:21

    Here is way too much information about member function pointers. There's some stuff about virtual functions under "The Well-Behaved Compilers", although IIRC when I read the article I was skimming that part, since the article is actually about implementing delegates in C++.

    http://www.codeproject.com/KB/cpp/FastDelegate.aspx

    The short answer is that it depends on the compiler, but one possibility is that the member function pointer is implemented as a struct containing a pointer to a "thunk" function which makes the virtual call.

提交回复
热议问题