simondopickup
asked on
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?
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
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Should it be C_simulation or C_Simulation? You refer to the latter in the question but in the code you use the former.
ASKER
Recursive dependancy - that is a new one..I will watch out for that. Thanks!
Well spotted I8 :)
I should have said "circular dependency" heh ;) It's not really recursive due to the #pragma once.
>> Recursive dependancy - that is a new one
A useful read: http://www.gamedev.net/reference/articles/article1798.asp
A useful read: http://www.gamedev.net/reference/articles/article1798.asp
>> 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.
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 */
ASKER
#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