Page 1 of 1

Structure Decalarations

Posted: Mon Apr 05, 2010 6:24 am
by dream_coder
Hey all, I am creating my character stats using a structure. Do I need to declare this structure in the main source code or can I do it in my Header file, in case I want to use it again?

Re: Structure Decalarations

Posted: Mon Apr 05, 2010 8:08 am
by MrDeathNote
dream_coder wrote:Hey all, I am creating my character stats using a structure. Do I need to declare this structure in the main source code or can I do it in my Header file, in case I want to use it again?
Yea you can put it in your header, it's fine if your gonna be reusing it.

Re: Structure Decalarations

Posted: Mon Apr 05, 2010 9:03 am
by dream_coder
I have declared it in a different header file but VC++ wont let me use it. Below is the code of my functions, this is where I am trying to use the structure in the CreateChar function.

Code: Select all

//Header guards

#ifndef ADD_H 
#define ADD_H 

#include "cus_structures.h"


//Function header, these are the declarations of functions I am using to make the program more friendly
//and reusable, will probably upgrade to classes in the near future, 

int DrawMenu();
void CreateChar();
void LoadGame();
void NewGame();

//This is the code for the above functions, notice how easier it is to modify these seperatly 
//from the main program

int DrawMenu()
{
	
	//Define local variable for menu option.
	int intChoice;

	system("cls");	//Clear the screen
		cout << "Please select an option: ";
		cout << endl;
		cout << "0: Create Character: " << endl;
		cout << "1: Load Game: " << endl;
		cout << "2: New Game: " << endl;
		cout << "3: Exit: " << endl;

		cout << "Please enter your choice: ";
		cin >> intChoice;

		return intChoice;


}

void CreateChar()
{
	int Pause;
	//Character Creation code, create a character then write it to file so it can be used later in a game.
	Stats NewPlayer;
	NewPlayer.life = 10;
	NewPlayer.magic = 10;
	NewPlayer.attack = 10;
	NewPlayer.defence = 10;

	system("cls");
	cout << "Please enter a name for your character: ";
	cin >> NewPlayer.CharName;

	system("cls");
	cout << "Here are your stats: "; << endl;
	cout << "Name: " << NewPlayer.CharName << endl;
	cout << "life: " << NewPlayer.life << endl;
	cout << "magic: " << NewPlayer.magic << endl;
	cout << "attack: " << NewPlayer.attack << endl;
	cout << "defence: " << NewPlayer.defence << endl;

	cin << Pause;



}

void LoadGame()
{
	//Some code here
}

void NewGame()
{
	//Some code here
}

#endif
And here is the header file where I declare the structure

Code: Select all

#ifndef MY_STRUCTS
#define MY_STRUCTS

struct Stats {
	string CharName;
	int life;
	int magic;
	int attack;
	int defence;

};




#endif
When I run this code VC++ will not recognise the structure when I try and create it
1>c:\users\cyberstu\documents\visual studio 2008\projects\project_stu\project_stu\functions.h(46) : error C2065: 'Stats' : undeclared identifier

Re: Structure Decalarations

Posted: Mon Apr 05, 2010 10:45 am
by GroundUpEngine
Yo, I ran this in VC++ it told me you had 44 errors, so I tryed it in Code::Blocks and it pointed out 2 obvious errors.
I'm not hating on VC++ "I'm just saying" :lol:

Line 60 -> Extra semi-colon

Code: Select all

cout << "Here are your stats: "; << endl;
Line 67 -> Operator is wrong way round

Code: Select all

cin << Pause;
Apart from that your code is fine ;)

Re: Structure Decalarations

Posted: Mon Apr 05, 2010 12:46 pm
by dream_coder
Cool cheers for that. By the way, without sounding stupid, what is Code Blocks??

Re: Structure Decalarations

Posted: Mon Apr 05, 2010 12:52 pm
by GroundUpEngine
dream_coder wrote:Cool cheers for that. By the way, without sounding stupid, what is Code Blocks??
Just another IDE like VC++ ;)

Re: Structure Decalarations

Posted: Mon Apr 05, 2010 4:55 pm
by mv2112
GroundUpEngine wrote:Yo, I ran this in VC++ it told me you had 44 errors, so I tryed it in Code::Blocks and it pointed out 2 obvious errors.
I'm not hating on VC++ "I'm just saying" :lol:
Thats why i always fix the first error on the list and rebuild, usually it fixes all errors :mrgreen:

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 3:21 am
by dream_coder
Fixed those two errors. Still not working in VC++. Gonna get Code Blocks now. Seems stupid that different compilers treat the same code differently.

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 9:19 am
by avansc
GroundUpEngine wrote:Yo, I ran this in VC++ it told me you had 44 errors, so I tryed it in Code::Blocks and it pointed out 2 obvious errors.
I'm not hating on VC++ "I'm just saying" :lol:

Line 60 -> Extra semi-colon

Code: Select all

cout << "Here are your stats: "; << endl;
Line 67 -> Operator is wrong way round

Code: Select all

cin << Pause;
Apart from that your code is fine ;)
Ummm, well there are a lot of things that contribute to this.
First of all, you probably have different warning level flags on the respective IDE's

For verbatim code, you ALL WAYS want to take the setup that gives you the most errors/warnings.

And lastly, the MS compiler is very very strict compared to GCC.

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 9:27 am
by thejahooli
avansc wrote:And lastly, the MS compiler is very very strict compared to GCC.
Which is actually a good thing because it stops you from thinking your code is fine when there are actually problems with it.

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 11:14 am
by GroundUpEngine
I agree with all the above, but the strictness of VC++ can be more annoying than helpful sometimes.

p.s. I set the warning/error flags real high in Code::Blocks so I get the feel of VC++ but I can still chill ;)

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 11:36 am
by Falco Girgis
GroundUpEngine wrote:I agree with all the above, but the strictness of VC++ can be more annoying than helpful sometimes.

p.s. I set the warning/error flags real high in Code::Blocks so I get the feel of VC++ but I can still chill ;)
Seriously? I think GCC is TEN MILLION times bitchier than Visual Studio.

It bitches about no newlines at end of file (just because the C++ standard doesn't mention how to handle it. Common effing sense). It WONT LET ME do something like call a function Move(Vector2) with Move(pos1-pos2), because all intermediate stack variables are implicitly cast to const. It also doesn't let you make an enumerated type forward declaration? What the fuck?

I find GCC inferior to VC++ in many, many ways. It seems as though "just because the standard doesn't specifically mention every tiny thing" they don't even bother implementing it. I use GCC for the DC/PSP builds and VS2008 for Windows. I like VS a million times better.

When I build the engine, I usually have 0 errors and warnings on the PC and something like 20 warnings on the PSP/DC

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 11:45 am
by avansc
GyroVorbis wrote:
GroundUpEngine wrote:I agree with all the above, but the strictness of VC++ can be more annoying than helpful sometimes.

p.s. I set the warning/error flags real high in Code::Blocks so I get the feel of VC++ but I can still chill ;)
Seriously? I think GCC is TEN MILLION times bitchier than Visual Studio.

It bitches about no newlines at end of file (just because the C++ standard doesn't mention how to handle it. Common effing sense). It WONT LET ME do something like call a function Move(Vector2) with Move(pos1-pos2), because all intermediate stack variables are implicitly cast to const. It also doesn't let you make an enumerated type forward declaration? What the fuck?

I find GCC inferior to VC++ in many, many ways. It seems as though "just because the standard doesn't specifically mention every tiny thing" they don't even bother implementing it. I use GCC for the DC/PSP builds and VS2008 for Windows. I like VS a million times better.

When I build the engine, I usually have 0 errors and warnings on the PC and something like 20 warnings on the PSP/DC
Yea, GCC is not even ISO/IEC C99 compliment, it has entire chunks missing of the standard.

Intel makes a fantastic compiler aswell just FYI.

ps: i know you know the difference between a compiler and IDE, but i see you compare gcc and visual studio with respect to the compilers, the compiler used in visual studio by default is cl.exe, just incase you didn't know the name.

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 1:37 pm
by GroundUpEngine
@Gyro
I'm trying not to imply GCC is better in any way, shape, or form. It's just I have never experienced these things you speak of and I don't really use Visual Studio as much as I used too. Although after reading this, I'm tempted to port my engine back to VC++ and break out of some bad habits ;)

@avansc
hmm, from reading this it seems I like GCC because it's 'dirty' and I can get away with shit. Don't worry I'm not very proud of my self right now :lol:

Re: Structure Decalarations

Posted: Tue Apr 06, 2010 8:56 pm
by eatcomics
The only problem I've had with VS is that I've not been able to get more than a simple window up when it comes to win32, I'm guessing its just something I'm doing wrong, but can't for the life of me figure it out... where as code::blocks and dev-cpp both compiled and ran fine, so IDK...