Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ array initializer. Using enum type

class ARouter {
    enum directions {north, neast, east, seast, south, swest, west, nwest};
    static directions gon[] = {north, neast, nwest, east, west, seast, swest, south};
};

Hi, does anyone know what is the matter with the above code?

I am getting 2 errors for the second line from VC++2008Ex:

error C2059: syntax error : '{'

error C2334: unexpected token(s) preceding '{'; skipping apparent function body

like image 403
John Avatar asked Mar 05 '26 17:03

John


1 Answers

You cannot define a variable inside a class like that.

It needs to be something like:

class ARouter {
    enum directions {north, neast, east, seast, south, swest, west, nwest};
    static directions gon[];
};

ARouter::directions ARouter::gon[] = {north, neast, nwest, east, west, seast, swest, south};

The declaration goes in the class body; the definition lives outside. Note that you'd typically put the class body in a header, and the definition in a source file.

like image 138
Oliver Charlesworth Avatar answered Mar 07 '26 05:03

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!