Structure Decalarations
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 34
- Joined: Sat Mar 27, 2010 5:16 pm
Structure Decalarations
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?
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: Structure Decalarations
Yea you can put it in your header, it's fine if your gonna be reusing it.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?
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
-
- Chaos Rift Newbie
- Posts: 34
- Joined: Sat Mar 27, 2010 5:16 pm
Re: Structure Decalarations
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.
And here is the header file where I declare the structure
When I run this code VC++ will not recognise the structure when I try and create it
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
Code: Select all
#ifndef MY_STRUCTS
#define MY_STRUCTS
struct Stats {
string CharName;
int life;
int magic;
int attack;
int defence;
};
#endif
1>c:\users\cyberstu\documents\visual studio 2008\projects\project_stu\project_stu\functions.h(46) : error C2065: 'Stats' : undeclared identifier
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Structure Decalarations
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"
Line 60 -> Extra semi-colon
Line 67 -> Operator is wrong way round
Apart from that your code is fine
I'm not hating on VC++ "I'm just saying"
Line 60 -> Extra semi-colon
Code: Select all
cout << "Here are your stats: "; << endl;
Code: Select all
cin << Pause;
-
- Chaos Rift Newbie
- Posts: 34
- Joined: Sat Mar 27, 2010 5:16 pm
Re: Structure Decalarations
Cool cheers for that. By the way, without sounding stupid, what is Code Blocks??
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Structure Decalarations
Just another IDE like VC++dream_coder wrote:Cool cheers for that. By the way, without sounding stupid, what is Code Blocks??
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Structure Decalarations
Thats why i always fix the first error on the list and rebuild, usually it fixes all errorsGroundUpEngine 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"
-
- Chaos Rift Newbie
- Posts: 34
- Joined: Sat Mar 27, 2010 5:16 pm
Re: Structure Decalarations
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
Ummm, well there are a lot of things that contribute to this.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"
Line 60 -> Extra semi-colonLine 67 -> Operator is wrong way roundCode: Select all
cout << "Here are your stats: "; << endl;
Apart from that your code is fineCode: Select all
cin << Pause;
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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
- thejahooli
- Chaos Rift Junior
- Posts: 265
- Joined: Fri Feb 20, 2009 7:45 pm
- Location: London, England
Re: Structure Decalarations
Which is actually a good thing because it stops you from thinking your code is fine when there are actually problems with it.avansc wrote:And lastly, the MS compiler is very very strict compared to GCC.
I'll make your software hardware.
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Structure Decalarations
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
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
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Structure Decalarations
Seriously? I think GCC is TEN MILLION times bitchier than Visual Studio.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
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
Yea, GCC is not even ISO/IEC C99 compliment, it has entire chunks missing of the standard.GyroVorbis wrote:Seriously? I think GCC is TEN MILLION times bitchier than Visual Studio.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
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
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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Structure Decalarations
@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
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
Re: Structure Decalarations
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...