Undeclared Identifier

Hi,
I am including my Simulation header file yet the compiler is not recognising my Simulation Class C_Simulation that is part of the vector list - see below. I am getting an 'undeclared identifier' error. It is puzzling - can anyone help?


#include "Simulation.h"
 
using namespace std;
 
class C_manager																
{																			
private:
	int actor_id;
 
public:
	C_manager():actor_id(0){}												// Zero argument constructor
	vector<C_simulation> all_sims;	<=====ERROR										// Create a vector of C_simulation objects(exercises) as part of scan
	vector<C_simulation>::iterator all_sims_iter;							// Create an iterator for the vector stored C_simulation objects(exercises)
============================SIMULATION.H===============================
#pragma once
 
#include <string> 
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include "Aircraft.h"
#include "Sector.h"
#include "Manager.h"
#include "Global_Functions.h"
 
using namespace std;
 
 
class C_simulation												// The base class to hold basic C_simulation data
{
private:														
	string name;												// i.e PANSA
	string date;												// i.e 03122008
	string scenario;											// i.e AREFBASE													
	string sim_start_time;										// i.e 09:15
 
public:
	vector<int>actor_id;										// Vector containers of all C_actor id's part of the exercise object
	multiset <C_Aircraft, less<C_Aircraft> >ac_set;				// Declaration of an STL set called ac set to store aircraft of this exercise
	map <string,int>count_map;									// Declaration of an STL MAP to assist in counting functions
	multiset <C_Aircraft, less<C_Aircraft> >::const_iterator aircraft_iter;	// Declare an interator to the aircraft storage container
	map <string,int>::iterator ac_map_iter;						// Declare an iterator to the count map container
	multiset <C_sector, less<C_sector> >sector_set;				// STL set called sector_set as a member of simulation object					// 
	multiset <C_sector, less<C_sector>>::iterator sector_iter;	// STL iterator called sector_iter to the simulation object sector set
 
			
    C_simulation(string n, string d, string s, string st):name(n),date(d),scenario(s),sim_start_time(st) // 4 argument constructor
	{}
	C_simulation():name(""),date(""),scenario(""),sim_start_time("")		// No argument constructor
	{}
 
	string const & getname() const								// An accessor for the private member name
		{return name;}
	string const & getdate() const								// An accessor for the private member date
		{return date;}
	string const & getscenario() const							// An accessor for the private member scenario
		{return scenario;}
	
	void show_sim()const;																	// Declarator to show sim function that displays exercise object data
	void display_aircraft_count();															// Declarator to function to show aircraft that are members of the the exercise object
	void add_sector(string s, string t, string c, float v, float l, float f)const;			// Add a new sector to the exercise object
	void display_sectors();																	// Display stored sector objects
	
};

Open in new window

simondopickupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

simondopickupAuthor Commented:
Sorry - I am including all of the following along with Simulation.h

#pragma once

#include <string>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include "Actor.h"
#include "Simulation.h"

using namespace std;

class C_manager...

I am still having no luck                              
0
Infinity08Commented:
Your simulation.h file also includes your Manager.h file, so you've got a recursive dependency ...

I don't see any use of the C_manager class inside the simulation.h file, so just remove the #include <manager.h> from it, and try again.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
evilrixSenior Software Engineer (Avast)Commented:
Should it be C_simulation or C_Simulation? You refer to the latter in the question but in the code you use the former.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

simondopickupAuthor Commented:
Recursive dependancy - that is a new one..I will watch out for that. Thanks!
0
evilrixSenior Software Engineer (Avast)Commented:
Well spotted I8 :)
0
Infinity08Commented:
I should have said "circular dependency" heh ;) It's not really recursive due to the #pragma once.
0
evilrixSenior Software Engineer (Avast)Commented:
>> Recursive dependancy - that is a new one
A useful read: http://www.gamedev.net/reference/articles/article1798.asp
0
Infinity08Commented:
>> I will watch out for that. Thanks!

Btw, you can avoid most of those by only including those includes files that you absolutely need. If that still leaves you with a circular dependency, you can usually resolve them with forward declarations.

Just as an example, your simulation.h file should really look like below.

You probably also want to look into passing more things by reference rather than by value.
It might also be useful to store pointers (rather than the objects themselves) in the STL containers, but that depends on how you're using them. There is an advantage to using pointers however (with regard to the current question), and that's that a forward declaration is sufficient, and you can get rid of one more include.

I'm also a bit wary of all those publicly accessible STL containers ... Is that intentional ? Usually you want to hide the implementation details from the user, and not give the user direct access to a class' data.
#ifndef SIMULATION_H          // <--- use include guards rather than #pragma once
#define SIMULATION_H
 
#include <string>
#include <vector>
#include <set>
#include <map>
 
#include "Aircraft.h"
#include "Sector.h"
 
//#include <iostream>          // <--- don't need these
//#include <fstream>
//#include "Manager.h"
//#include "Global_Functions.h"
 
//using namespace std;         // <--- don't dump a whole namespace into a header file
 
 
class C_simulation                                                                                              // The base class to hold basic C_simulation data
{
private:                                                                                                                
        std::string name;                                                                                            // i.e PANSA
        std::string date;                                                                                            // i.e 03122008
        std::string scenario;                                                                                        // i.e AREFBASE                                                                                                 
        std::string sim_start_time;                                                                          // i.e 09:15
 
public:
        std::vector<int> actor_id;                                                                            // Vector containers of all C_actor id's part of the exercise object
        std::multiset<C_Aircraft, less<C_Aircraft> > ac_set;                         // Declaration of an STL set called ac set to store aircraft of this exercise
        std::map<std::string,int> count_map;                                                                      // Declaration of an STL MAP to assist in counting functions
        std::multiset<C_Aircraft, less<C_Aircraft> >::const_iterator aircraft_iter; // Declare an interator to the aircraft storage container
        std::map<std::string,int>::iterator ac_map_iter;                                         // Declare an iterator to the count map container
        std::multiset<C_sector, less<C_sector> >sector_set;                         // STL set called sector_set as a member of simulation object                                   // 
        std::multiset<C_sector, less<C_sector> >::iterator sector_iter;      // STL iterator called sector_iter to the simulation object sector set
 
                        
    C_simulation(std::string n, std::string d, std::string s, std::string st):name(n),date(d),scenario(s),sim_start_time(st) // 4 argument constructor
        {}
        C_simulation():name(""),date(""),scenario(""),sim_start_time("")                // No argument constructor
        {}
 
        std::string const & getname() const                                                          // An accessor for the private member name
                {return name;}
        std::string const & getdate() const                                                          // An accessor for the private member date
                {return date;}
        std::string const & getscenario() const                                                      // An accessor for the private member scenario
                {return scenario;}
        
        void show_sim()const;                                                                                                                                   // Declarator to show sim function that displays exercise object data
        void display_aircraft_count();                                                                                                                  // Declarator to function to show aircraft that are members of the the exercise object
        void add_sector(std::string s, std::string t, std::string c, float v, float l, float f)const;                  // Add a new sector to the exercise object
        void display_sectors();                                                                                                                                 // Display stored sector objects
        
};
 
#endif /* SIMULATION_H */

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.