c++ - Does the standard make any guarantee that adding a constructor does not change the size? -
lets have class
struct foo { uint32_t x; uint32_t y; };
does c++ standard make mention whether sizeof(foo)
should same sizeof(bar)
if bar
adds constructor ?
struct bar { uint32_t x; uint32_t y; bar(uint32_t = 1,uint32_t b = 2) : x(a),y(b) {} };
the reason why asking foo
send across network void*
, cannot change size, if possible add constructor.
i found related: here , here, there answers focus on virtuals changing size , looking more definite "[...] implementations know of [...]".
ps: avoid misunderstanding... not asking how constsruct foo
, send void*
nor asking workaround make sure size not change, curious, whether standard says sizeof
in specific case.
c++ 98 guarantees layout “plain old data” objects , don't permit constructors.
c++ 11 introduces “standard layout types”, still guarantee layout, permit constructors , methods added (and permits non-virtual bases added exceptions empty classes , duplicates).
Comments
Post a Comment