I'm trying to initialize a static member variable from a sizeof of a non-static:
class Myclass
{
int a;
static const int b = sizeof(a);
};
This should be legal with c++11, right? It gives me compiler error C2327 ("a is no typename not static and no enumerator).
Compiler is Visual Studio 2015 Express.
This is obviously a bug in VC++, as in 19.00.23506, sizeof(Myclass::a) doesn't work. This seems to have been fixed somewhere between versions 19.00.23506 (try online rextester) and 19.00.23720.0 (try online Microsoft). You may try to report the bug or download a newer build of the IDE/compiler.
Still, I would report a bug anyways since the nested name specifier shouldn't be required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With