Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] qtcreator "Expected class-name before '{' token"
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] qtcreator "Expected class-name before '{' token"

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 8.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    heatblazer
    wrote on 28 Nov 2014, 11:57 last edited by
    #1

    Hello, I have a simple code, which, following a simple logic - must work. But I get that expected class-name before { token in my .h file. What is this??? Here is the code:
    @
    #include <QList>
    #include "ActionEllipseItem.h"

    class ActionEllipseItem;
    class MainWindow;

    class GameLogic {
    friend class ActionEllipseItem;
    friend class MaindWindow;
    public:
    virtual void checkConditions()=0;
    virtual void getReport(ActionEllipseItem*) = 0;
    virtual ~GameLogic()=0;
    private:

    };
    @

    And the class that must implement the functions:
    @
    #include "GameLogic.h"
    #include "ActionEllipseItem.h"

    class ActionEllipseItem;

    class GameOfNumbers : GameLogic { /* THE ERROR LINE*/
    public:
    void checkConditions();
    void getReport(ActionEllipseItem*);
    GameOfNumbers() ;
    ~GameOfNumbers();

    private:
    };
    @
    Qt reports me this strange error. Really no idea why.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 28 Nov 2014, 12:22 last edited by
      #2

      You are using forward declaration for ActionEllipseItem, but you also include it's header file. One needs to be removed, in both header files.

      You need to specify the mode of inheritance:
      @
      class GameOfNumbers : public GameLogic
      // or
      class GameOfNumbers : private GameLogic
      @

      (Z(:^

      1 Reply Last reply
      0
      • C Online
        C Online
        Chris Kawa
        Lifetime Qt Champion
        wrote on 28 Nov 2014, 12:24 last edited by
        #3

        It's not Qt reporting it. It's the compiler.

        The odd thing I see is that you include ActionEllipseItem.h and then forward declare ActionEllipseItem. The point of forward declaration is so that you don't have to include the declaring header in another header. Maybe something in that header confuses the compiler?

        Unrelated: Not an error, but you are not specifying the access type in your inheritance declaration. The default is private. Is that intended here? Even if so, I would still go for an explicit declaration for the future reader.

        Also, a pure virtual destructor is also unusual. Not an error though.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JKSH
          Moderators
          wrote on 28 Nov 2014, 12:25 last edited by
          #4

          Hi,

          You forgot the access-specifier.

          @
          // Using the "public" access specifier:
          class GameOfNumbers : public GameLogic {
          ...
          };
          @

          EDIT: Triple answer! :D

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Binary91
            wrote on 28 Nov 2014, 12:27 last edited by
            #5

            Hi,
            you know that you don't use an access specifier? That would mean private inheritance and then, you can't access public stuff...

            [EDIT] Arrgh, so many people faster than me xD

            1 Reply Last reply
            0
            • H Offline
              H Offline
              heatblazer
              wrote on 28 Nov 2014, 12:30 last edited by
              #6

              Yes, I want to inherit all. It was not the public specifier. Mr Chris Kawa was right. It`s including the .h file. Thnaks, these C++ feats are confusing as hell!

              1 Reply Last reply
              0
              • C Online
                C Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on 28 Nov 2014, 12:34 last edited by
                #7

                bq. these C++ feats are confusing as hell!

                Just at the beginning. Don't get discouraged ;)

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  heatblazer
                  wrote on 28 Nov 2014, 12:40 last edited by
                  #8

                  Will try to do so...

                  1 Reply Last reply
                  0

                  1/8

                  28 Nov 2014, 11:57

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved