类的函数为什么在sizeof中反映不出来。
#include <iostream>
class Base
{
public:
void f();
int g();
private:
int i;
};
int main()
{
Base b;
int i = sizeof(b);
return 0;
}
如上例,sizeof的值为4。
但是这并不代表不占空间,因为类的函数代码,放在代码段(Code Segment)。
The sizeof operator cannot be used with the following operands:
Functions. (However, sizeof can be applied to pointers to functions.)
Bit fields.
Undefined classes.
The type void.
Dynamically allocated arrays.
External arrays.
Incomplete types.
Parenthesized names of incomplete types.