![]() |
How to use enums
Hi I made a class for notes and want to use an enum for a status like NEW or DELETED but I can't get it to work.
Heres the code: note.h Code:
#ifndef NOTE_H Code:
#include "note.h" Can anyone tell me how to write this correctly? |
Re: How to use enums
enums must be defined in the header file - not the cpp.
|
Re: How to use enums
The compiler is telling you what's wrong. The compiler is your friend.
"without previous declaration" indicates that you need to move the declaration of your enum to a place where it has been seen before you use it. I'd suggest after the include and before the class declaration. The compiler is your friend. |
Re: How to use enums
Quote:
|
Re: How to use enums
Quote:
Code:
public: |
Re: How to use enums
Quote:
Code:
enum Status And yes, I wanna use this enum also outside the class. ;) |
Re: How to use enums
Quote:
Quote:
So, I think that we agree on how it should be done, you just got it a little bit too general in your answer. |
Re: How to use enums
Code:
#ifndef NOTE_H |
Re: How to use enums
Quote:
Code:
enum Status Hint: Your enum is a symbol that's not part of the class. An enum is a place holder for integer values and nothing more. If you want to limit its visibility, use namespaces or declare it inside your class. Hint 2: If you want to get help with compiling things, paste all of what the compiler is complaining about together with the offending part of code. In this case, a line number would have been nice. Happy hacking. |
Re: How to use enums
I'm now using the last version that nicolai has posted and everything works just fine. Thanks for your help. :)
The only problems I have now is my limited knowlage about * and & symbols before variables. so I have to deal with several "can not convert int* to int" errors.. :o Maybe someone could post a little summary about the meaning of int i, int *i and int &i. And why my compiler forbids me to do the following: QDateTime *time; time = QDateTime::currentDateTime(); |
All times are GMT. The time now is 00:27. |
vBulletin® Version 3.8.8