Need Urgent Help Fixing Errors in Program

I'm creating a space simulator program for uni and I've got 3 errors that I just can't seem to fix. I need help ASAP as it needs to be in tomorrow morning, if anyone has time to help ,I'd be grateful and even pay for your time in exchange for fixing my errors.

Thanks

Dan
If you can post your code and the error messages here, someone here can try to help.

If you post code - please use code tags ... just highlight the code and click the <> button in the Format palette on the right side of the post.
What help do you expect without posting the code?
there's not enough characters for me to upload my whole code. Any suggestions? Can I upload zip files or anything
Post the first 2 or 3 errors and the lines of code they reference.

We'll probably ask you to post definitions for things we don't understand.
You can't upload zip files.
Can you isolate the problem to a small subset of code?
You can post your code in multiple messages, but doing so runs the risk that people won't look at it if it's too long.

Failing that, post the exact text of your error messages, That might give some insight to your issues.
Error 1 error C2065: 'Items' : undeclared identifier
Error 2 error C2059: syntax error : '>'
Error 3 error C2976: 'std::list' : too few template arguments

its all to do with this list >>
list <Items*> spaceItems;

switch (itemChoice)
{
case 1:
description = "Ufo";
Items* newItem;
newItem = myItemFactory->newItems(description);
spaceItems.push_front(newItem);
break;
case 2:
description = "moon";
newItem = myItemFactory->newItems(description);
spaceItems.push_front(newItem);
break;

I'm trying to populate the list but it's not liking the syntax
list <Items*> spaceItems;

Items* newItem;

If Items is being reported as an undeclared identifier, that means the compiler has not seen the declaration for Items yet. Have you included the appropriate header?

As for the syntax error on '>', I suspect the undefined reference to Items is causing this error also.

With regard to std::list number of arguments, if Items is undefined, that can explain "too few template arguments".

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Last edited on
Here is my EmptySpace.h file with headers (Observer)
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
/******************************
Observer pattern - Observer
******************************/

#ifndef EMPTYSPACE_H
#define EMPTYSPACE_H
#include <iostream>
#include "ItemControls.h"
#include "ItemFactory.h"
#include <list>
#include "Items.h"
using namespace std;

class EmptySpace
{
public:

	EmptySpace();
	~EmptySpace();
};

class ItemInterface 
{

public:
	int i;
	int itemChoice;
	string description;
	void itemMenu();
	list <Items*> spaceItems;

	ItemInterface();
};


and here is the Items.cpp and .h file

// Items.cpp file
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
38
39
40
41
42
43
44
45
#include "Items.h"
using namespace std;

void Items::setName(string aName)
{
	name = aName;
}

string Items::getName(string aName)
{
	return name;
}

void Items::setTemp(double newTemp)
{
	temp = newTemp;
}

void Items::setSoundAbility(Sound* newSoundAbility){

	soundAbility = newSoundAbility;
}

void Items::tryToMakeSound()
{
	soundAbility->makeSound();
}

Ufo::Ufo()
{
	setSoundAbility(new CanMakeSound());			
}

void Sound::makeSound()
{
}

void  CanMakeSound::makeSound(){							
	cout << "BeepBeepBeepBeepBeep";
}

void  CannotMakeSound::makeSound(){							

	cout << "Cannot make noise";
}


/******************************
Factory pattern - Items.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <list>
#include <string>
#include "EmptySpace.h"
using namespace std;

class Items
{

	//Sound* soundAbility;

public:
	string sound;
	string name;
	double temp;
	double velocity;
	double position;

	class Sound* soundAbility;
	virtual void setName(string aName);
	virtual string getName(string aName);
	virtual void setTemp(double temp), getTemp(double temp);
	virtual void setVelocity(double velocity), getVelocity(double velocity);
	virtual void setPosition(int position), getPosition(int position);
	virtual void setSoundAbility(Sound* newSoundAbility);
	void tryToMakeSound();

};

class Ufo : public Items
{
public:

	Ufo();
	void update(int temp, double velocity, int position);

};

class Moon : public Items
{
public:
	void update(int temp, double velocity, int position);
};

class Junk : public Items
{
public:
	void update(int temp, double velocity, int position);
};

class Satellite : public Items
{
	void update(int temp, double velocity, int position);
};

class Asteroid : public Items
{
	void update(int temp, double velocity, int position);
};

class Comet : public Items
{
	void update(int temp, double velocity, int position);
};

class Rocket : public Items
{
	void update(int temp, double velocity, int position);
};

class SpaceStation : public Items
{
	void update(int temp, double velocity, int position);
};

class Astronaut : public Items
{
	void update(int temp, double velocity, int position);
};

class Sound
{

public:
	virtual void makeSound();
};

class CanMakeSound : public Sound
{
public:
	void makeSound();
};

class CannotMakeSound : public Sound
{
public:
	void makeSound();
};


And in case you need it, here's the factory part of the factory pattern

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************
Factory pattern - ItemFactory.h
******************************/
#ifndef ITEMFACTORY_H
#define ITEMFACTORY_H
#include "Items.h"
#include <iostream>
#include "EmptySpace.h"
#include <list>
using namespace std;

class ItemFactory
{
public:
	class Items *newItems(string &description);
	ItemFactory();
	~ItemFactory();
};
#endif 


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
#include "ItemFactory.h"
Items *newItems(string &description)
{
	{
		if (description == "Ufo")
		return new Ufo;										
		if (description == "Moon")
			return new Moon;
		if (description == "Satellite")
			return new Satellite;
		if (description == "Asteroid")
			return new Asteroid;
		if (description == "Comet")
			return new Comet;
		if (description == "Rocket")
			return new Rocket;
		if (description == "SpaceStation")
			return new SpaceStation;
		if (description == "Astronaut")
			return new Astronaut;
	}
}

ItemFactory::~ItemFactory()
{
}

What I see are circular includes.
emptyspace.h includes items.h and items.h includes emptyspace.h
That in itself is not a problem, but I don't see a proper forward declaration of the other class in either header.

items.h line 19: What is this supposed to be? Is this supposed to be a forward declaration, or a pointer variable? class keyword is unneeded. I don't see a declaration of Sound. Any compile errors in the declaration of the Items class, will generally cause the class to be undefined.

itemfactory.h line 15: Again what is this supposed to be? A forward, or a pointer?


Last edited on
This
1
2
3
4
#include "ItemFactory.h"
Items *newItems(string &description)
{
	{


should be this.
1
2
3
4
#include "ItemFactory.h"
Items *ItemFactory::newItems(string &description)
{
	{

The description should probably be passed by const ref.
Topic archived. No new replies allowed.