CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2011
    Posts
    2

    [RESOLVED] Error - "undefined class"

    Hi everyone. I'm fighting with this thing since yesterday and can't get any idea what's wrong. Here's the code of my Headquarters.h:

    Code:
    #ifndef HEADQUARTERS_H
    #define HEADQUARTERS_H
    #include "node.h"
    #include "Main_trucks_list.h"    //Isn't it defined here?
    #include "Main_firefighters_list.h"    //And here?
    #include <string>
    
    using namespace std;
    
    class Firebrigade;
    class Accident;
    class Main_trucks_list; 
    class Main_firefighters_list;
    
    class Headquarters
    {
    private:
    	Main_trucks_list my_main_trucks_list;  //ERROR HERE
    	Main_firefighters_list my_main_firefighters_list;   //ERROR HERE
    	node<Accident>* accident_head;	
    	node<Firebrigade>* firebrigade_head;	
    	string town;
    	string street;
    	friend class Accident;
    	friend class Firebrigade;
    	friend class Firefighter;
    	friend class Truck;
    
    public:
    	node<Firebrigade>* get_firebrigade_head() const;	
    	bool insert_firebrigade(Firebrigade*);			
    	bool delete_firebrigade(string address);		
    	bool create_accident(string place, unsigned how_many_firefighters);		
    	unsigned count_accidents() const;				
    	bool remove_accident(unsigned id);				
    	void display_accidents() const;					
    	Headquarters(string town, string street);		
    	~Headquarters();						
    };
    
    #endif
    The errors:
    Code:
    Error	1	error C2079: 'Headquarters::my_main_trucks_list' uses undefined class 'Main_trucks_list'	c:\users\pawel\desktop\c++ project\fire brigade\fire brigade\headquarters.h	20

    Code:
    Error	2	error C2079: 'Headquarters::my_main_firefighters_list' uses undefined class 'Main_firefighters_list'	c:\users\pawel\desktop\c++ project\fire brigade\fire brigade\headquarters.h	21
    I can't understand why I get that. In lines 12 and 13 I declared the classes which are defined in their headerfiles. What's the problem?


    Additional:

    Main_trucks_list.h:
    Code:
    #pragma once
    #include "Truck.h"
    
    class Truck;
    
    class Main_trucks_list
    {
    private:
    	node<Truck>* head;
    
    public:
    	bool insert_truck(Truck*);
    	bool remove_truck(unsigned id);
    	Main_trucks_list(void);
    	~Main_trucks_list(void);
    	Truck* find(unsigned id) const;
    };
    Main_firefighters_list.h:
    Code:
    #pragma once
    #include "Firefighter.h"
    
    class Firefighter;
    
    class Main_firefighters_list
    {
    private:
    	node<Firefighter>* head;
    
    public:
    	bool insert_firefighter(Firefighter*);
    	bool remove_firefighter(unsigned id);
    	Main_firefighters_list(void);
    	~Main_firefighters_list(void);
    	Firefighter* find(unsigned id) const;
    };
    Please, help me, I'm going crazy...

  2. #2
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Error - "undefined class"

    Hi,

    Note the difference between undefined and undeclared.

    You have declared the class, but not defined it. So you could use a pointer to it in your Headquarters class (which is probably what you want to do anyway), but if you want to add it as an object the compiler needs to know what size etc, so it has to be defined.

  3. #3
    Join Date
    May 2011
    Posts
    2

    Re: Error - "undefined class"

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured