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

前端 未结 4 975
轮回少年
轮回少年 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:10

    Use

    sizeof(int (MyClass::*)())
    

    since you're taking the "size of a member function pointer of MyClass that returns int and takes no arguments".

提交回复
热议问题