Structure for use in multiple files

Started by
3 comments, last by Joshnathan 19 years, 4 months ago
Hi all, I have this structure:

struct WORLD
{
       SDL_Surface *image;
       int value;
       int x, y;
};

and I NEED it in more then one source file(.cpp). how can I make 2 instances of this struct without the compiler telling me I am causin an error? Thanks, Joshua
-----------------------------Sismondi GamesStarted c++ in October 2004...
Advertisement
this should be of some help.
put that struct into a .h file, then #include that .h file from your two .cpp files.
FTA, my 2D futuristic action MMORPG
ok, I am sorry if I was unclear, but I am not a TOTAL newie to c++.
I offcourse put my struct into a header file, and I used
#ifndef _WORLD_H#define _WORLD_H#include <SDL/SDL_image.h>extern struct WORLD{       SDL_Surface *image;       int value;       int x, y;};WORLD world[40][30];#endif


But when I include them into 2 source files(.cpp), I get the following error:
hero.cpp C:\WINDOWS\Desktop\Joshua\RPG\hero.o(.bss+0x0) multiple definition of `world'

I hope this is clearer,
Joshua
-----------------------------Sismondi GamesStarted c++ in October 2004...
ok, I fixed the problem. I didn't know I could "extern" my "WORLD world[40][30]. Thanks everyone for trying to help me out :D
-----------------------------Sismondi GamesStarted c++ in October 2004...

This topic is closed to new replies.

Advertisement