How to apply sizeof() operator to non-static class member methods?

前端 未结 4 982
轮回少年
轮回少年 2021-01-25 11:00
struct MyClass {
  int foo () { return 0; }
};

unsigned int size = sizeof(MyClass::foo);  // obviously error

Can we apply sizeof() to mem

4条回答
  •  花落未央
    2021-01-25 11:16

    iirc this would return size of function pointer anyways, so why do that? Or am I mistaken?

    Edit: I was mistaken, this is invalid code, event if function were out of class. All you can do with sizeof and function is get size of function pointer(which you need to make first). If you want to get size occupied by function code you'll need some other way to get that.

    Some further reading: http://msdn.microsoft.com/en-us/library/4s7x1k91(v=vs.71).aspx

提交回复
热议问题