2

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;

MyLDC::Attributes

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?

3
  • 2
    And what error do you get? Please include the full error, complete and unedited, in the question body. Commented Oct 28, 2016 at 10:06
  • Unrelated to your error, symbol names starting with an underscore and followed by an upper-case letter are reserved for the implementation (compiler and standard library). See e.g. this old SO answer for more information. Commented Oct 28, 2016 at 10:07
  • Error: Attributes' is not a class or namespace| Commented Oct 28, 2016 at 10:24

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

2 Comments

@JoeMartiniello: Glad to be of some help. I've been there before as well :)
Sorry I didn't get. It seems to be working in my case: ideone.com/4KyrH6 What different I am doing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.