|
2011-04-04
, 10:09
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#2
|
|
2011-04-04
, 10:11
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#3
|
The Following User Says Thank You to Joorin For This Useful Post: | ||
|
2011-04-04
, 10:12
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#4
|
|
2011-04-04
, 10:24
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#5
|
No. Symbols need to be declared before they are used. If this enum was to be internal, it might very well be declared in the cpp file.
public: enum Status
|
2011-04-04
, 10:27
|
Guest |
Posts: n/a |
Thanked: 0 times |
Joined on
|
#6
|
enum Status { NORMAL = 0, NEW = 1, DELETED = 2 };
|
2011-04-04
, 10:29
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#7
|
Yes you are right, but his:
looks like he doesn't want to use it internally only.Code:public: enum Status
enums must be defined in the header file - not the cpp.
The Following User Says Thank You to Joorin For This Useful Post: | ||
|
2011-04-04
, 10:41
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#8
|
#ifndef NOTE_H #define NOTE_H #include <QObject> class Note : public QObject { Q_OBJECT public: Note(QString Text); Note(int Id, QString Text); enum Status { NORMAL = 0, NEW = 1, DELETED = 2 }; private: int id; QString text; Status status; }; #endif // NOTE_H
|
2011-04-04
, 10:43
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#9
|
So, I put that code between the include and class in the header file:
But I get the same error: "use of enum 'Status' without previous declaration".Code:enum Status { NORMAL = 0, NEW = 1, DELETED = 2 };
And yes, I wanna use this enum also outside the class.
enum Status { NORMAL = 0, NEW = 1, DELETED = 2 }; class Note { public: Note(); Note(int Id); private: int id; Status status; }; Note::Note() { id = 0; status = NEW; } Note::Note(int Id) { id = Id; status = NORMAL; } int main(int argc, char** argv) { Note foo; return 0; }
The Following User Says Thank You to Joorin For This Useful Post: | ||
|
2011-04-04
, 11:55
|
Guest |
Posts: n/a |
Thanked: 0 times |
Joined on
|
#10
|
Heres the code:
note.h
Can anyone tell me how to write this correctly?