0

I have the following struct:

typedef struct{
    static const uint8_t foo = 10;
    uint8_t bar;
}foobartype_t;

When I say:

uint32_t foobarSize = sizeof(foobartype_t);

or

foobartype_t foobar;
foobar.bar = 20;
uint32_t foobarSize = sizeof(foobar);

it returns 1. Why? Environment is Qt 5.3.2 (MSVC 2010, 32 bit).

Sebastian Lange
  • 3,879
  • 1
  • 19
  • 38
Raipe
  • 153
  • 7
  • Static members don't contribute to the size of the object. There's just one instance of such member for the whole class, not one embedded into each instance of that class. – Igor Tandetnik Dec 17 '14 at 04:28
  • What does it have to do with Qt? By the way, if it is a Qt codebase, please use quint8 or if you only support C++11 and on, use constexpr instead of const. – László Papp Dec 17 '14 at 04:36

0 Answers0