Why doesn't my structure work, I did the same thing as the tutorial on this site!
struct ship
{
int x_pos;
int y_pos;
};
ship player;
player.x_pos = 256;
player.y_pos = 256;
Printable View
Why doesn't my structure work, I did the same thing as the tutorial on this site!
struct ship
{
int x_pos;
int y_pos;
};
ship player;
player.x_pos = 256;
player.y_pos = 256;
Hi,
I cant see anything wrong with that code all i can think is that you have it in the wrong place: here is a complete working example:
That compiles fine in Visual C++ 6.Code:#include <iostream.h>
struct ship
{
int x_pos;
int y_pos;
};
int main()
{
ship player;
player.x_pos = 256;
player.y_pos = 256;
return 0;
}
Hope that helps
TNT
No, that isn't it.
Im defining this in a header file, does that make any differnece??
I couldn add variables inside a header file.
I moved it outside the header file into a cpp file and now it works.
I should have looked a t my sig more :D
> player.x_pos = 256;
This line has to be inside a function - there is no problem with the rest of your original post being in a .h file.