Sonya Blade
Sonya Blade

Reputation: 399

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)

Upvotes: 0

Views: 601

Answers (2)

Tristan Brindle
Tristan Brindle

Reputation: 16824

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.

Upvotes: 0

molbdnilo
molbdnilo

Reputation: 66371

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.

Upvotes: 1

Related Questions