Results 1 to 2 of 2

Thread: [ubuntu] [enums] enums error: does not name a type

  1. #1
    Join Date
    Aug 2015
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default [ubuntu] [enums] enums error: does not name a type

    I have a c++ class TrisState:

    Qt Code:
    1. #ifndef TRISSTATE_H
    2. #define TRISSTATE_H
    3.  
    4. #include <QObject>
    5. #define WIDTH 3
    6. #define HEIGHT 3
    7. class TrisState : public QObject
    8. {
    9. Q_OBJECT
    10. Q_ENUMS(GameState)
    11. public:
    12. explicit TrisState(QObject *parent = 0);
    13. GameState x();
    14.  
    15. enum GameState {
    16. Player1 = 'X',
    17. Player2 = 'O',
    18. Draw = '-',
    19. Void = ' '
    20. };
    21.  
    22. private:
    23. GameState board[WIDTH][HEIGHT];
    24.  
    25. signals:
    26.  
    27. public slots:
    28.  
    29. };
    30.  
    31. #endif // TRISSTATE_H
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. #include "trisstate.h"
    2.  
    3.  
    4. TrisState::GameState TrisState::x()
    5. {
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    When i compile the code i've two errors:
    trisstate.h:13: error: 'GameState' does not name a type
    GameState x();
    ^

    and

    trisstate.cpp:4: error: no 'TrisState::GameState TrisState::x()' member function declared in class 'TrisState'
    TrisState::GameState TrisState::x()
    ^

    What am i wrong?

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [ubuntu] [enums] enums error: does not name a type

    Hello,

    in the header file first declare the enum before using it:
    Qt Code:
    1. enum GameState {
    2. Player1 = 'X',
    3. Player2 = 'O',
    4. Draw = '-',
    5. Void = ' '
    6. };
    7.  
    8. GameState x();
    To copy to clipboard, switch view to plain text mode 

    Best regards
    ars
    Last edited by ars; 28th August 2015 at 14:44. Reason: reformatted to look better

Similar Threads

  1. Using namespace enums in headers
    By Phlucious in forum General Programming
    Replies: 3
    Last Post: 30th November 2011, 01:28
  2. How to use enums in qml
    By nightroad in forum Qt Quick
    Replies: 0
    Last Post: 29th June 2011, 13:24
  3. Save enums in QSettings
    By redhat in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2009, 11:22
  4. Using enums in QtScript
    By Orphelic in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 11:55
  5. how to use enums
    By soul_rebel in forum General Programming
    Replies: 3
    Last Post: 23rd March 2006, 21:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.