does not name a type ERROR

This is a discussion on does not name a type ERROR within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm having trouble compiling, after writting a few lines of code, suddenly my compiler throws me an error. The ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    54

    does not name a type ERROR

    Hi,

    I'm having trouble compiling, after writting a few lines of code, suddenly my compiler throws me an error. The error is :

    GameWorld.h:38: error: ‘AsteroidList’ does not name a type

    Here's the code that is related :

    GameWorld.h
    Code:
    #ifndef GAMEWORLD_H
    #define GAMEWORLD_H
    #include <iostream>
    #include <cstdlib>
    #include <sstream>
    #include <fstream>
    #include <QApplication>
    #include <QGridLayout>
    #include <QPushButton>
    #include <QPainter>
    #include <list>
    #include <vector>
    
    #include "AsteroidList.h"
    #include "Asteroid.h"
    #include "AsteroidType1.h"
    #include "AsteroidType2.h"
    #include "Player.h"
    #include "t_List.h"
    
    using std::cout;
    using std::istringstream;
    using std::ifstream;
    using std::string;
    using std::cin;
    using std::list;
    using std::vector;
    
    class GameWorld
    {
      Player p;
      list<Asteroid*> L;
      list<Asteroid*>::iterator i;
      vector<Asteroid*> V;
      t_List<Asteroid*> tList;
    
      public:
        // Error is here
        AsteroidList li;
        void loadData(char*,char*,int);
        void drawPlayer(QPainter&);
        void drawAsteroid(QPainter&);
    
      private:
        int dataType;
    };
    
    #endif
    Here is my header file for #include "AsteroidList.h"
    Code:
    #ifndef ASTEROIDLIST_H
    #define ASTEROIDLIST_H
    #include <QPainter>
    #include <vector>
    #include <list>
    
    #include "AsteroidNode.h"
    #include "Asteroid.h"
    #include "AsteroidType1.h"
    #include "AsteroidType2.h"
    #include "GameWorld.h"
    
    using std::cout;
    using std::vector;
    
    class AsteroidList
    {
      public:
        AsteroidList();
        AsteroidNode* first() const;
        void addAsteroidPoint(string,float,float);
        void addAsteroid(string,float,float,int,int,int);
        void drawAsteroids(QPainter&, int, string,int,float,float);
        void drawAsteroid(QPainter&, QPolygonF,float,float);
        void checkAsteroids(QPainter&, int);
        void display();
        void setNull();
    
      private:
        Asteroid *a_first;
    };
    
    #endif
    I have no idea what happened. Can anyone share any ideas?

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    "GameWorld.h" #includes "AsteroidList.h" that #includes "GameWorld.h"
    Get rid of all the unnecessary #includes in your headers.
    Headers should only #include what is necessary for them to compile.
    e.g. I don't see a reason why "AsteroidList.h" should #include "GameWorld.h"
    Kurt

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    Try including AsteroidList after

    #include "Asteroid.h"
    #include "AsteroidType1.h"
    #include "AsteroidType2.h"

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    54
    Thanks alot! I'm sorry about my unnessary includes because my assignment happened to be so large I sometimes get really messed up. Its the first time I'm doing C++.

    Thanks ZuK and Desolation!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21