简体   繁体   English

将构造函数中的枚举作为参数传递

[英]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" 枚举在全局范围内声明为以下形式,PSLGVertex :: PSLGVertex()构造函数抱怨最后一个参数,即其“ PSLGVertexType'不是类或名称空间”

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. 您正在使用PSLGVertexType:: ,它告诉编译器PSLGVertexType是类/结构或名称空间,但两者都不是。

Use plain OTHER_VERTEX . 使用普通的OTHER_VERTEX

In C++-03, enum members are placed in the enclosing scope. 在C ++-03中, enum成员位于封闭范围内。 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中,您的代码会很好,因为将成员放置在封闭范围(为了向后兼容)和内部枚举范围中。

C++11 also has new scoped enums , which you can read about on Wikipedia . C ++ 11还具有新的作用域枚举 ,您可以在Wikipedia上进行阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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