简体   繁体   中英

passing enum in constructor as an argument

Enumeration is declared as follow in global scope, PSLGVertex::PSLGVertex() constructor complains about the last argument that its "PSLGVertexType' is not a class or namespace"

What am I doing wrong here ?

enum PSLGVertexType {
REFLEX_VERTEX,
CONVEX_VERTEX,
MOVING_STEINER_VERTEX,
MULTI_STEINER_VERTEX,
RESTING_STEINER_VERTEX,
OTHER_VERTEX
};

Constructor

PSLGVertex::PSLGVertex() : mark(false), oriPosition(0, 0), speed(0, 0), 
startTime(0.0),firstin(NULL), firstout(NULL),type(PSLGVertexType::OTHER_VERTEX)

You're using PSLGVertexType:: , which tells the compiler that PSLGVertexType is a class/struct or a namespace, but it's neither.

Use plain OTHER_VERTEX .

In C++-03, enum members are placed in the enclosing scope. So don't say

 PSLGVertexType::OTHER_VERTEX

but rather just

 OTHER_VERTEX

In C++11, your code would be fine, as the members are placed in both the enclosing scope (for backward compatibility) and in the inner enum scope as well.

C++11 also has new scoped enums , which you can read about on Wikipedia .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM