struct{
	int   health;
	int   armor;
	char* wep_name;
	char* name;
} test_player = {
	100,
	10,
	"master sword",
	"tom"
};

how to i access the members of test_player ?

test_player.health

You can manipulate it like a normal variable, aka get and set the value :D

Hello tomtetlaw,

As JugglerDrummer mentioned above, you would use the member access operator "." For more information on the operator and structures in general (including pointers to structures and the member access operator through a pointer "->") you should take a look at the following website:
http://cplusplus.com/doc/tutorial/structures/

-D

when i use the . i get these errors:
main.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(53) : error C2143: syntax error : missing ';' before '.'
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(53) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(53) : error C2371: 'test_player' : redefinition; different basic types
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(47) : see declaration of 'test_player'

when i use the . i get these errors:
main.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(53) : error C2143: syntax error : missing ';' before '.'
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(53) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(53) : error C2371: 'test_player' : redefinition; different basic types
c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\main.cpp(47) : see declaration of 'test_player'

Post your code so we can see what you have on the lines that you're receiving errors on.

-D

- error C2143: syntax error : missing ';' before '.'
- missing type specifier - int assumed. Note: C++ does not support default-int
- 'test_player' : redefinition; different basic types
struct{
	int   health;
	int   armor;
	char* wep_name;
	char* name;
} test_player = {
	100,
	10,
	"master sword",
	"tom"
};
test_player.health = 1;

thisis ym code

struct{
	int   health;
	int   armor;
	char* wep_name;
	char* name;
} test_player = {
	100,
	10,
	"master sword",
	"tom"
};
test_player.health = 1;

thisis ym code

OK, that's your code, but WHERE is it? If line 12 is not inside of a function, you have problems. If it's before main, outside of a function, try sticking it in main and see if it works better. You'll get the same error if you stick something like this in the global scope:

int a = 6;
a = 8;

Second line gives an error. Stick it in main.

I am not sure about this , But does this happen because all of the global elements are constructed only at the start of main ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.