# include & lt; iostream>
using namespace std;
Class A
{
Public:
Int c=3;
int a=1;
Int b=2;
};
Int main (int arg c, char * argv [])
{
Cout
Cout & lt;
return 0;
}
12
123
Please press any key to continue...
Class did not allocate space during the definition???????
Why sizeof (A) would be 12 bytes
Can't class when defined initialization???????
Cout & lt;
Class did not allocate space during the definition???????
Why sizeof (A) would be 12 bytes
this is more easy to explain, sizeof is not really A function, it is A macro, it evaluated for any type of variable is done at compile time rather than execution, that is to say in execution, size_t x=sizeof (A) has become A size_t x=12 such constants assignment statements,
CodePudding user response:
C + + 11 featuresNon - static data member initializers
Sizeof got the corresponding type footprint size,
CodePudding user response:
Best to write code to initialize, encoder automatic initialization is uncertainCodePudding user response:
Sizeof operator