Function parameters reading as expressions

I keep getting this error:

error C2065: 'mainchar_values' : undeclared identifier
error C2065: 'player' : undeclared identifier
error C2065: 'background' : undeclared identifier
error C2275: 'background_values' : illegal use of this type as an expression
: see declaration of 'background_values'
error C2062: type 'float' unexpected

The file that the error occurs in.
Screen_Manager.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
#pragma once

#include <allegro5/allegro.h>
#include <string>
#include <iostream>
#include "Sprite.h"

#define DISP_WIDTH 640
#define DISP_HEIGHT 480
#define ALEXANDRIA_DEFUALT_BACKGROUND_X 0
#define ALEXANDRIA_DEFUALT_BACKGROUND_Y 147
#define ALEXANDRIA_DEFUALT_CHAR_X 341
#define ALEXANDRIA_DEFUALT_CHAR_Y 432

class FieldBuilder{
	private:
		float* recs;
		int recs_length;

	public:
		FieldBuilder(const char* filepath, int numOfRecs);
		bool isWithin(float points[]);
};

struct background_values{
	float sourceX;
	float sourceY;
	float x;
	float y;
	float *charX;
	float *charY;
	short int* dir;
	ALLEGRO_BITMAP *background;
	background_values(float sx, float sy, float dx, float dy, float* cx, float* cy, short int* cd, ALLEGRO_BITMAP *bg);
};

void sm_calc_background_values(background_values* bv);

void sm_draw_background(background_values* bv);

void mv_val_to_bv_val(mainchar_values *player, background_values* background, float points[]); //This is where the error is occurring. 


Screen_Manager.cpp function definition
1
2
3
4
void mv_val_to_bv_val(mainchar_values* player, background_values* background, float points[]){
	points[0] = *player->x + background->sourceX;
	points[1] = *player->y + background->sourceY;
}


Sprite.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
#pragma once

#include <allegro5/allegro.h>
#include "Screen_Manager.h"

#define MAINCHAR_MOVESPEED 5
#define MAINCHAR_SOURCEX_LEFT 0
#define MAINCHAR_SOURCEY_LEFT 0
#define MAINCHAR_SOURCEX_RIGHT 188
#define MAINCHAR_SOURCEY_RIGHT 8
#define MAINCHAR_SOURCEY2_RIGHT 64
#define MAINCHAR_SOURCEX_UP 0
#define MAINCHAR_SOURCEY_UP 104
#define MAINCHAR_SOURCEX_DOWN 0
#define MAINCHAR_SOURCEY_DOWN 52
#define MAINCHAR_WIDTH 30
#define MAINCHAR_HEIGHT 49

enum SPRT_KEYS{
	KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
};

struct mainchar_values{
	float sourceX;
	float sourceY;
	float *x;
	float *y;
	short int dir;
	bool keys[4];
	ALLEGRO_BITMAP* image;
	mainchar_values(float sx, float sy, float* dx, float* dy, short int direction, bool arr[4], ALLEGRO_BITMAP* img);
};

I have tried defining other functions with struct mainchar_values as parameters in Screen_Manager.h and it seems that, that is the only one that causes an error.
I am also able to create instances of struct mainchar_values in my main class.
Last edited on
Hi, a quick thought...

I see that on line 34 in struct background_values you declare what looks like a function. It may be complaining that there is no return type, and in addition to your declaration in your header file the compiler is expecting a function definition.

Assuming background_values has a void return type, I'd try putting this into your Screen_Manager.cpp implementation file:
1
2
3
4
void background_values::background_values (float sx, float sy, float dx, float dy, float* cx, float* cy, short int* cd, ALLEGRO_BITMAP *bg)
{
	// Some code here
}


But then again, it's late and I could be off in La-La land. Hope this helps...
Actually that's the constructor that I have for background values, which I do have a definition for in the cpp file. If I comment out that function where the error occurs everything else runs smoothly, its just when I try to put mainchar_values as a parameter that things goof up.
You haven't declared your mainchar_values class before the my_val_to_bv_val function. It probably screwed over the other parameter declarations since the compiler couldn't deal with the first one.
1
2
3
4
void my_val_to_bv_val(mainchar_values *player, background_values* background, float points[]);
//-->
void my_val_to_bv_val(*player background_values,* background float, points[]);
//Maybe 


Thankfully, you're using a pointer for mainchar_values. All you have to do is prototype mainchar_values above somewhere. This is a way to promise your compiler that you've defined this class later on.
Awesome, the prototype of the struct before hand worked.

I wonder why the compiler needs that prototype since I'm including the header file that contains the struct...

If anyone has any idea as to why this is, I would like to know.
Maybe your compiler went through Sprite.h first, which then led it to Screen_Manager.h. In that order, mainchar_values has never been declared yet.

Anyway, you should try to avoid such includes within header files. Prefer prototyping versus including an entire file you may or may not need. This will help you avoid problems like this one.
Last edited on
Cool, thanks for the tip.
Topic archived. No new replies allowed.