Thread: Multiple Classes And Header Files error does not name a type

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    29

    Question Multiple Classes And Header Files error does not name a type

    When ever I try to program programs with a few classes and headers in different files sometimes it gives me

    error: some_class does not name a type

    for example I have the following classes in different files:

    Canimatedtile
    Clayer
    Cmap

    and map is declared some what like this (Please excuse some of the syntax errors in my real files there are no syntax errors)

    Code:
    #include "layer.h"
    
    class Cmap
    {
    public:
        Clayer layer[6]; //6 tile layers
    }
    and layer is declared like this

    Code:
    #include "animatedtile.h"
    class Clayer
    {
    public:
        int tiles[256][256]; //256*256 tile map
        Canimatedtiles animatedtiles[20];
    }
    It will give me this error in map.h:
    Code:
    error: Clayer does not name a type
    It happens with other things that I try to program that also have multiple classes; I get simular results with those. I am using an IDE. I know very little about makefiles, but my guess is that the makefile the IDE is generating is in the wrong order.

    What I am basically asking is what should I do to avoid and fix these types of errors?

    Thank you for suggestions and help.

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Place the ';' after the '}' of classes.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Always add header include guards to your header files.

    Be careful of recursive dependencies. In your example it should be ok, but those might be causing that error in your real code. You cannot have a class with a member variable of one type, and have that type have a member variable of the first class. If you need that to happen, use some sort of indirection, like a pointer, or instead of a static array use a vector or dynamic array. Then you don't have to #include the other header file and you can use a forward declaration instead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Defining multiple classes in the same header file
    By Stonehambey in forum C++ Programming
    Replies: 2
    Last Post: 08-14-2008, 10:36 AM
  2. Header files and classes
    By disruptivetech in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2008, 09:02 AM
  3. Strange problem with classes in header files
    By samGwilliam in forum C++ Programming
    Replies: 2
    Last Post: 02-29-2008, 04:55 AM
  4. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM