c++ sizeof() of a class with functions

后端 未结 7 944
情深已故
情深已故 2020-12-01 10:38

I have a C++ question. I wrote the following class:

class c
{
    int f(int x, int y){ return x; }
};

the sizeof() of class c returns \"1\"

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 11:11

    1 means 1 byte. And the reson is that methods are not stored within an object. They are used by objects, but not stored in them. Only class members are stored in objects. Try to add a plain int member or something and see what happens.

提交回复
热议问题