Getting the size of member variable

前端 未结 7 406
猫巷女王i
猫巷女王i 2020-12-15 17:34

If there is a POD structure, with some member variables, for example like this:

struct foo
{
   short a;
   int b;
   char c[50];
   // ...
};
7条回答
  •  甜味超标
    2020-12-15 18:15

    C++-0x allows you to do this:

      std::cout << sizeof( foo::a ) << std::endl;
      std::cout << sizeof( foo::b ) << std::endl;
      std::cout << sizeof( foo::c ) << std::endl;
    

    C++-0x allows sizeof to work on members of classes without an explicit object.

    The paper is here: Extending sizeof to apply to non-static data members without an object (revision 1)

    I saw the post about this above too late. Sorry.

提交回复
热议问题