On Sat, 21 Jan 2023 16:34:55 -0000 (UTC)
Mut...@dastardlyhq.com wrote:
>On Sat, 21 Jan 2023 11:23:54 -0500
>Sorry, I meant what is the point of the curly brackets after "unsigned char"
>in the definition. You can put identifiers between them but they seem to be
>ignored and it fails to compile if you try to use them. eg:
>
>fenris$ cat t.cc
>enum class mybyte : unsigned char {a,b,c};
>
>int main()
>{
> mybyte b{1};
> mybyte c{a};
>}
>fenris$ c++ -std=c++17 t.cc
>t.cc:6:11: error: use of undeclared identifier 'a'
> mybyte c{a};
> ^
>1 error generated.
>fenris$
I realise replying to yourself is bad form but I was being thick - I needed
to qualify the identifier. This works as expected outputting 1 and 2:
#include <iostream>
enum class mybyte : unsigned char {a,b,c};
int main()
{
mybyte b1{1};
mybyte b2{mybyte::c};
std::cout << (int)b1 << ", " << (int)b2 << std::endl;
}