Joe Martiniello Joe Martiniello - 1 year ago 124
C++ Question

C++ Enum in struct error for definition

Hello im a newbie from C++.
For a my project i need to use a enum value similar C# example.

My Struct

struct Rows
string name;
bool primaryKey;
int lenght;
string defined;
MyLDC::Attributes attrib;
bool Nullable;
bool AutoIncrement;
string comment;

Rows rw;
Rows* row = &rw;


enum Attributes
_BINARY = 0x26,
_UNSIGNED = 0x27

My Example function

void MyLDC::CreateTable(string tablename,string primaryKey)

//Simple Row Implementation
row->name = "Example Row";
row->AutoIncrement = true;
row->primaryKey = true;
row->comment = "Example Row";

row->attrib = Attributes::_UNSIGNED;

I get error on row->attrib = Attributes::_UNSIGNED;

no have idea for this error.
who are the correct solution?

Answer Source
enum Attributes
    _BINARY = 0x26,
    _UNSIGNED = 0x27
row->attrib = Attributes::_UNSIGNED;

My psychic debugging powers ;) tell me that the problem is that the _UNSIGNED symbol is not under the scope of Attributes, so you should be able to do:

row->attrib = _UNSIGNED;

For scoped enums you may want to use C++11's enum class.

P.S. Note also that _Upper (underscore followed by uppercase letter) names are reserved for implementations, and should not be used in your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download