C++Builder Learn How To Use C++ Extending Sizeof For Windows Development

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Learn How To Use C++ Extending Sizeof For Windows Development
January 21, 2021 by Pabitra Dash

Given some class C with a data member m,
C++:
struct C {
   some_type m;
   // ...
};
the current standard makes it ill-formed to refer to m in sizeof expressions without providing an object. For example, uses such as sizeof(C::m) (outside of C) or sizeof(m) (in a static member of C) are ill-formed.

C++11 extends the functionality of sizeof so that class members can be sent as parameters even if no object has been instantiated.
C++:
struct S {
  int m;
};
int i = sizeof(S::m);       // ok
int j = sizeof(S::m + 42);  // error: reference to non-static member in subexpression
The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is an unevaluated operand, or a parenthesized type-id.

Для просмотра ссылки Войди или Зарегистрируйся