Error - undeclared identifier, but I think I declared it.

Hi everybody.

I'm doing my project which I was assigned at my C++ classes. It's about fire brigades. I created the basic classes and member functions declarations. However, in one class I get the error and I cannot come up with any idea how to solve it. Here is the thing.

The template I use (node.h):
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef NODE_H
#define NODE_H
#include "Firefighter.h"

template <typename T>
struct node
{
	T* object;
	node<T>* next;
};

#endif 



This is my header file "Firebrigade.h":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef FIREBRIGADE_H
#define FIREBRIGADE_H

#include <string>
#include "node.h"
#include "Firefighter.h"
#include "Truck.h"

using namespace std;

class Firebrigade
{
private:
	node<Firefighter>* firefighter_head; //HERE'S THE ERROR
	node<Truck>* truck_head;	//HERE'S THE ERROR
	string address;
	Firefighter* commander;

public:
	//if already hired, just make commander, if not, hire and then make commander; if hired somewhere else - error
	void make_commander(unsigned firefighter_id);	
	void unmake_commander();	//Making the current commander again a regular firefighter.
	void hire_firefighter(unsigned id);		//if already hired - error
	void fire_firefighter(unsigned id);
	void display_firefighters();
	void assign_truck(unsigned id);			//if already assigned - error
	void delete_truck(unsigned id);
	void display_trucks();
	Firebrigade(string address);
	~Firebrigade();
};

#endif 


That's "Firefighter.h":
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef FIREFIGHTER_H
#define FIREFIGHTER_H
#include <string>
#include "Firebrigade.h"
using namespace std;

class Firefighter
{
public:
	enum rank_type
	{
			firefighter,
			sergeant,
			lieutenant,
			captain,
			battalion_chief,
			division_chief,
			assistant_chief,
			chief
	};

private:
	Firebrigade* which_firebrigade; //Describes to which unit the firefighter belongs.
	unsigned id;	//unique ID
	string name;
	rank_type what_rank;
	bool on_mission;	//Whether the firefighter is currently on a mission or not.

public:
	void promote();
	Firefighter(unsigned id, string name, rank_type what_rank);
	~Firefighter();


}; 
#endif 


I'm using Visual Studio 2010. While trying to build solution, I get errors:
Error 1 error C2065: 'Firefighter' : undeclared identifier c:\users\pawel\desktop\c++ project\fire brigade\fire brigade\firebrigade.h 14

Error 2 error C2065: 'Truck' : undeclared identifier c:\users\pawel\desktop\c++ project\fire brigade\fire brigade\firebrigade.h 15

Any ideas what's wrong?
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef NODE_H
#define NODE_H
#include "Firefighter.h"

template <typename T> //ERROR MAY BE HERE USE  "class"
struct node
{
	T* object;
	node<T>* next;
};

#endif  


hello there,
I'm noob in C++ but what I've learned so far I thik u shlould use "class identifier" and not "typenamde" in this template.

like this:

template <class T>
struct node {....};

cos typename can't be replaced with class name and class can be with both.

and u have use class name in "Firebrigade.h" on line 14 and 15 (but allowed is typename.
Last edited on
I think... When you include "Node.h", it includes "Firefighter.h", which includes "Firebrigade.h" before any of the class definitions. Just add class Firefighter; (after the includes, before the class) in "Firebrigade.h". Your probably having a similar problem with "Truck.h".
Thanks! It helped!
Last edited on
Topic archived. No new replies allowed.