Thread: error: expected class-name before ‘{’ token

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    81

    error: expected class-name before ‘{’ token

    Really don't understand why I get the compile error. I put a big arrow on the line this error appeared on. I've tried rearranging the order of the includes and stuff like that, but even if that worked I wouldn't understand why.

    Code:
    ----MAIN.cpp----------------
    #include <G3D/G3DAll.h>
    #include <GLG3D/GLG3D.h>
    
    #include "App.h"
    #include "Demo.h"
    
    
    int main(int argc, char** argv) 
    {
    	GAppSettings settings;
    	settings.window.width = 800;
    	settings.window.height = 600;
    
    	App app(settings);
    	app.setDebugMode(true); 
    	app.debugController.setActive(true);
    
    	app.run();
    	return 0;
    }
    
    -----DEMO.h-------------------
    
    #ifndef Demo_H
    #define Demo_H
    
    #include <G3D/G3DAll.h>
    #include <GLG3D/GLG3D.h>
    #include "App.h"
    
    class Demo : GApplet {                   <<<<-----------------------------Here's the ERROR  
     public:
      Demo(App* app) : app(app) {}
        void doGraphics();
    
     private:
        const App* app;
    };
    
    #endif
    
    
    ------APP.h------------------
    #ifndef App_H
    #define App_H
    
    #include <G3D/G3DAll.h>
    #include <GLG3D/GLG3D.h>
    #include "Demo.h"
    
    class App : public GApp {
     public:
      App(const GApp::Settings& settings): GApp(settings) {} 
    		void main();
    };
    
    #endif
    
    -------APP.cpp---------------
    
    #include "App.h"
    
    void App::main()
    {
    	Demo(this).run(); 
    }
    
    ------DEMO.CPP-------------
    
    #include "Demo.h"
    
    void Demo::doGraphics() {
      app->renderDevice->clear(true, true, true);
      app->renderDevice->setProjectionAndCameraMatrix(app->debugCamera);
      Draw::axes(Vector3(0,4,0),app->renderDevice);
    }
    Last edited by keira; 12-21-2007 at 01:05 AM.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Is GApplet defined in one of those header files?
    You should also be explicit about what kind of inheritance you want (i.e. public, protected or private), otherwise people might just think you forgot to add the keyword...

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Spelling perhaps?

    I see 'App' and 'GApp', but no 'GApplet'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You're mixing spaces and tabs - bad. Use ONE and stick with it. I recommend tabs.
    And come on - one space for indentation - that's kind of cheap, isn't it? Use AT LEAST 4 spaces if you're going for spaces.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You have a recursive include between app.h and demo.h. There's no reason for app.h to include demo.h.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    81
    yeah I thought recursive include or something like that so I've been messing around with the include statements... Nothing works though.

    The line in question should be "class Demo : public GApplet {"

    I just don't understand this error.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you have referencing headers, then you must use a forward declaration, like
    Code:
    class GApplet;
    ...before the code that uses it. Then include the proper header file inside the .cpp file.
    It's difficult to test this because many of the required classes are missing, so it won't compile properly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Instead of including App.h in Demo.h, use a forward declaration:
    Code:
    class App;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I still don't see anything in App.h that references Demo.h's contents in any way.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-19-2008, 12:10 PM
  2. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  3. Replies: 7
    Last Post: 05-26-2005, 10:48 AM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM