#define

I have been having a problem with my code for quite a while now. It started with trying to reference a const static int of a class in the same class. It caused a strange problem which disallowed any class from reading any of its variables. Even after removing the new code, the problem persisted (and still does). I decided to change from consts to #define-ing all of my constants instead for the time being.

There is quite a bit of code, so if someone feels up to the task then just request the code and I will post it all.

I am desperate and will be incredibly grateful to anyone who even attempts to help or gives my something to try.
I would just upload the code to pastebin or something and then it will be easier for people to see.

But I can try and help you out with it however you want to show the code.
You could try a complete project rebuild. In Code::Blocks this is Build->Rebuild. I have found that sometimes only this will clear old dependencies and eliminate ugly, persistent linker errors.
jim hurley wrote:
...So if someone feels up to the task then just request the code and I will post it all.

Well, Post it and We'll show you if we are up to the task or if we aren't.

Yes, this is a request ^^
I'm sorry it took me so long to reply, I don't quite understand this site and I thought I had email notifications on but I didn't.

http://pastebin.com/GiTWBZGA

I have also limited it down to being an error with reading the "definitions" header file from another header file.

However, there are other problems with the "Figure.h" to tackle also. Thank you for your patience if you are kind enough to help me still.

NOTE if you feel for some reason the rest of the code is necessary ( it's just more header files that function properly except won't read the definitions either ) just let me know.
Last edited on
Does Definitions.h include Headers.h?
Oh I'm sorry, Headers.h should be called Definitions.h. Just a typo.
In that case the problem is that Definitions.h includes Figure.h. If Definitions.h is included before Figure.h has been included, Figure.h will be included by Definitions.h. Figure.h will try to include Definitions.h but nothing will be included because #pragma once prevents the header from being included more than once so when the Figure class is defined the constants has not yet been defined. The solution is to remove #include "Figure.h" from Definitions.h.
Last edited on
Let me give you all of my code, because that creates more errors.

What is the easiest way to send you all of the .cpp and .h files?
~I'm going to work now, I will be back later tonight, I hope you continue to help me
Well I use dropbox which is really easy if you plan on using and holding it. Otherwise you can use http://localhostr.com and upload a zip.
I applied what @Peter87 said to all of my code, and it worked! The only error I have now is when I try to reference my struct outside of Figure.h.

In the header, I have a struct defined as follows:

1
2
3
4
5
6
7
//Figure index
struct FIGURE_TYPE {
	//Where to crop the image from
	SDL_Rect crop;
	int x;
	int y;
};


It is a pretty simple concept. It has a rectangle that tells where to crop the image from out of the image file, and an x and y to point out where it will be added to the screen. However, when I try to make an array of these structs a parameter to a function, I get an error.

void set_camera ( SDL_Rect& camera, Figure::FIGURE_TYPE figure_index[FIGURE_COUNT] );

The errors:

Error 1 error C2653: 'Figure' : is not a class or namespace name
Error 2 error C2061: syntax error : identifier 'FIGURE_TYPE'

I realize that its just a syntax error on how I reference the struct, but I can't make heads or tails of it. Would you mind explaining it so I can be done with this mess?
Have you defined FIGURE_TYPE inside the Figure class body?
1
2
3
4
5
6
7
8
9
10
11
12
class Figure {
public:
	struct FIGURE_TYPE {
		//Where to crop the image from
		SDL_Rect crop;
		int x;
		int y;
	};
	
	...
	
};


If you define FIGURE_TYPE outside the class you have to leave out Figure:: in front of FIGURE_TYPE.
void set_camera ( SDL_Rect& camera, Figure::FIGURE_TYPE figure_index[FIGURE_COUNT] );
Last edited on
It's because:
1. FIGURE_TYPE is probably in the global namespace. Remove Figure::.
2. You cannot pass this parameter like that.

You can perhaps:

void set_camera(SDL_Rect& camera, FIGURE_TYPE* figure_index);
@Peter87 Yes, I did define it inside the Figure class body.
@EssGeEich Although I don't quite understand your fix, I tried it and it didn't work. It says that FIGURE_TYPE is undefined then.
Topic archived. No new replies allowed.