c++ sizeof() of a class with functions

后端 未结 7 903
情深已故
情深已故 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:37

    The class contains no data members, so it's empty. The standard demands that every class have at least size 1, so that's what you get. (Member functions aren't physically "inside" a class, they're really just free functions with a hidden argument and a namespace and access control.)

    0 讨论(0)
提交回复
热议问题