Stack Overflow Asked on November 4, 2021
Given the c++ keyword decltype and illustrating with a code example:
int main(){
int variableName = 0;
sizeof(variableName) == sizeof(decltype(variableName));//Always true for all types? And for all expressions?
//
//
double variableDoubleName = 0;
sizeof(variableName+variableDoubleName) == sizeof(decltype(variableName+variableDoubleName));//further example of an expression.
}
In the example above, and in general, are sizeof(non-type) and sizeof(decltype(non-type)) always and strictly equivalent? If not, how would they differ?
Yes.
You might be imagining trouble from decltype
variously returning a reference type or a value type, depending on whether you give it an identifier or an expression (ref).
But, fortunately for us:
When applied to a reference type, the result [of
sizeof
] is the size of the referenced type. (ref)
So, it doesn't matter.
Answered by Asteroids With Wings on November 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP