classes, inheritance and include problems

This is a discussion on classes, inheritance and include problems within the C++ Programming forums, part of the General Programming Boards category; My problem looks as follows. I've got two classes Unit which is a base class for infantry they're in separate ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    classes, inheritance and include problems

    My problem looks as follows. I've got two classes Unit which is a base class for infantry they're in separate files

    infantry.h
    Code:
    #ifndef JB_INFANTRY_H_INCL
    #define JB_INFANTRY_H_INCL
    
    #include"main.h"
    #include"Unit.h"
    
    class Infantry : public Unit
    {
      public:
      Infantry();
      ~Infantry();
    
      UnitType unittype();
      void heal();
      void fortify();
    
      private:
      int fortification;
    };
    
    #endif
    unit.h
    Code:
    #ifndef JB_UNIT_H_INCL
    #define JB_UNIT_H_INCL
    
    #include"main.h"
    
    class Unit
    {
      public:
        
      Unit();
      virtual ~Unit();
    
    
      void SetOwner(OwnerType towhat);
      void SetHealth(int towhat);
      void SetActionpoints(int towhat);
      void SetPosition(int towhat[]);
      void SetListposition(int towhat);
    
      int GetAtt();
      int GetDef();
      OwnerType GetOwner();
      int GetActionpoints();
      int GetHealth();
      int GetMaxap();
      int *GetPosition();
      int GetListposition();
    
      UnitType virtual unittype();
      void virtual heal();
      //void virtual action(int direction);
    
      //add attack and move
    
      protected:
    
      int att,def,actionpoints,listposition,maxap,health,position[2];
      OwnerType owner;
    };
    
    #endif
    problem is that when i'm compiling this i get error in infantry.h
    "11 C:\Dev-Cpp\Projects\KOS\Infantry.h expected class-name before '{' token "
    whats wrong ? I can't get it ?

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    return_type virtual whatever();

    should be

    virtual return_type whatever();

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    20
    hmm i correcteed it but i still get the same error. It looks like it didn't initialize class unit and don't recognize it...

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    could it be that you have something like
    Code:
    #include "Infantry.h"
    #include "Unit.h"
    in main.h ?
    Kurt

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    20
    no i haven't got it.
    I've tried to move all includes to main.h and only include main.h in all other files.
    but then it come out with some other even stranger errors.
    Damn and yesterday it was all working.

  6. #6
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    For a test I would comment out all the #includes in the headers, and put the #includes into the implementation files only. Be careful to get the order right. Then compile each module separately and see what happens.

    Kurt

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    20
    Edit: Thanks for help.I rearranged all includes and it's working fine now. I was also trying to use in unit class function that was using unit class element, i think that was a problem.
    Last edited by baniakjr; 12-12-2006 at 01:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance, overriding, problems
    By CodeMonkey in forum C++ Programming
    Replies: 8
    Last Post: 01-04-2007, 12:26 AM
  2. Class inheritance problems
    By Carolina in forum C++ Programming
    Replies: 6
    Last Post: 08-25-2006, 04:30 AM
  3. inheritance problems
    By generic83 in forum C++ Programming
    Replies: 5
    Last Post: 04-10-2005, 05:04 PM
  4. Problems with memory allocation in classes
    By MathFan in forum C++ Programming
    Replies: 6
    Last Post: 01-09-2005, 01:05 AM
  5. Classes & Inheritance
    By TankCDR in forum C++ Programming
    Replies: 5
    Last Post: 03-09-2002, 05:25 PM

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