Having wierd problem ASAP help please :)

Hello,
I am trying to create vector of a class on another class.
now i did created vector of different class in the same way i try to create for this class but this i time i get error:
1>C:\C++\SFML\BrickBreaker\BrickBreaker\gameState.h(34,9): error C2065: 'Addons': undeclared identifier

gameState.h code:
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
#pragma once
#include "gameLoop.h"	
#include "Defenitions.h"
#include "Player.h"
#include "ball.h"
#include "loadLevel.h"
#include <conio.h>
#include <ctime>
#include "Addons.h"

class gameState : public State
{
public:

	gameState(gameDataRef data);

	void init();
	void handleInput();
	void update(float dt);
	void draw(float dt);

private:

	gameDataRef _data;
	Sprite _background, _player;
	RectangleShape _shape;
	RectangleShape _line;
	Player* player = new Player;
	loadLevel* level = new loadLevel(1);
	Clock _clock;
	Text scoreTitle, score, levelTitle, levelText;

	vector<ball*> _balls;
	vector<Addons*> _effects;

	

	float playerX = 0, playerY =0;
	float playerMovementSpeed = 8.f;
	float scaleX = 1, scaleY = 1;
	bool _ballOut = false;
	int changer = 0;
	int _score = 0;
	int _level = 1;
	int _addonID = 0;

	void checkBallStatus();
};



and Addons.h code:
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
#include "Addons.h"

Addons::Addons(Player* player) {

	this->_player = player;
	//this->_id = id;

	this->addonTexture.loadFromFile(EFFECTS_PATH);
	this->_addon.setTexture(this->addonTexture);


	int tempX = 6, tempY = 15, distanceX = 171, distanceY = 61;

	switch (this->_id) {
	case 1:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 0, tempY + distanceY * 0, 152, 42));
		break;
	case 2:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 1, tempY + distanceY * 0, 152, 42));
		break;
	case 3:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 2, tempY + distanceY * 0, 152, 42));
		break;
	case 4:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 0, tempY + distanceY * 1, 152, 42));
		break;
	case 5:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 1, tempY + distanceY * 1, 152, 42));
		break;
	case 6:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 2, tempY + distanceY * 1, 152, 42));
		break;
	case 7:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 0, tempY + distanceY * 2, 152, 42));
		break;
	case 8:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 1, tempY + distanceY * 2, 152, 42));
		break;
	case 9:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 2, tempY + distanceY * 2, 152, 42));
		break;
	case 10:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 0, tempY + distanceY * 3, 152, 42));
		break;
	case 11:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 1, tempY + distanceY * 3, 152, 42));
		break;
	case 12:
		this->_addon.setTextureRect(IntRect(tempX + distanceX * 2, tempY + distanceY * 3, 152, 42));
		break;



	};
}

void Addons::move() {

	this->_addon.move(0,this->addonMoveSpeed);
}

void Addons::draw(RenderWindow& window) {

	this->move();
	window.draw(this->_addon);
}


if you look on gameState.h i did create ball vector ( different class) but i didnt get this err i cant find something wrong please help
thanks :)
and Addons.h code:
I assume here you meant that the code below is in Addons.cpp, right? Because if that really is Addons.h then that's really wrong.
You don't need the switch:

1
2
3
4
    _addon.setTextureRect(IntRect(tempX + distanceX * (_id - 1) % 3,
                                  tempY + distanceY * (_id - 1) / 3,
                                  152,
                                  42));

Last edited on

and Addons.h code:
I assume here you meant that the code below is in Addons.cpp, right? Because if that really is Addons.h then that's really wrong.


yes sir wrong copy paste xD this is addons.h

@dutch
okay i appriciate the help but im stuck with the VS err atm

addons.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#include "gameState.h"
#include "Defenitions.h"
#include "Player.h"

class Addons
{
public:
	Addons(Player* player);

	void move();
	void draw(RenderWindow& window);

private:
	Texture addonTexture;
	Sprite _addon;
	Player* _player;
	
	float addonMoveSpeed = 0.3f;
	int _id = 0;
};
The problem is that gameState.h includes Addons.h and Addons.h includes gameState.h. You can solve the problem by adding this in gameState.h right after the includes.

 
class Addons;  // forward declaration of Addons 

Actually, does gameState.h even need to be included in Addons? If it doesn't then just remove that include and you don't need the forward declaration.

BTW, "definitions" is spelled with an 'i' after the 'f'. :-)
Last edited on
Topic archived. No new replies allowed.