0

Consider an enum class

enum class FOO
{
  A,B,C
};

struct something
{
  FOO abc = FOO::A; //Compiler Doesnt like this
}

int main(){
  something _something;
  return 0;
}

So the compiler doesnt like the initialisation and gives me 3 different errors.

Error C2238 unexpected token(s) preceding ';'

Error C2059 syntax error: '='

Error C2653 'FOO': is not a class or namespace name


Compiler:

Visual C++

Build Tools MsVC142

So am I initialisation the enum incorrectly? or am i completely missing something.

11
  • Works on my machine. Can we see some context around it. Commented Sep 3, 2021 at 7:45
  • @WalleyM, Keeping the above enum class definition in mind. The enum is being initialized inside a struct so something like. struct something { FOO foo = FOO::A; } Commented Sep 3, 2021 at 7:56
  • 2
    Cannot reproduce, please provide a minimal reproducible example Commented Sep 3, 2021 at 7:59
  • 1
    @WalleyM not really sure how that's relevant? Commented Sep 3, 2021 at 8:06
  • 5
    You're missing a semicolon at the end of your struct definition };. Commented Sep 3, 2021 at 8:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.