Sign in to follow this  
SomePerson

I have Declarer issues can somebody help?

Recommended Posts

SomePerson    122
I'll be brief this time! I am working on my project (which is taking forever) and i have come to an issue. For some reason the compiler will not except my class or structs as declarers. EX-1: // in "ini.h" class INI {...}; // in "main.h" extern INI gIni; // this should create a global variable right? so then i tryed another thing but this does not work either... EX-2: // in "ini.h" struct INI {...}; // int "main.h" extern INI gIni; // again this should work right? Please somebody explain what I am doing wrong... I am brain dead right now... it's getting really late! Thanks for helping,!

Share this post


Link to post
Share on other sites
ApochPiQ    23064
The extern INI gIni; line does not create a variable; all it does is tell the compiler that somewhere there should be a variable of class INI called gIni. Any file that #includes main.h will be aware of this variable, but it doesn't exist just yet. In order to create that variable, you need to put this in one of your .cpp files (preferably main.cpp since gIni is forward declared in main.h):

INI gIni;



That should solve it for you.

Share this post


Link to post
Share on other sites
SomePerson    122
Yes i got that... I can get a lot of other extern + declarers to work but just not mine. When i enter in the extern INI gIni; The compiler gives an error saying declarer 'INI' unknown, but i have the #include "INI.h" at the top of the file? Why does it say the declarer is unknown if it is clearly there.
I did check spelling, caps and no caps, all that stuff? Any one got an ideal?

You can make classes and struct external right?

//EX:
stuct INI {...};
extern INI myINI; // < ---- This is legal right?

Share this post


Link to post
Share on other sites
crupp    122
Quote:
Original post by SomePerson

//EX:
stuct INI {...};
extern INI myINI; // < ---- This is legal right?


In C++, yes, in C, no, you'd need

struct INI {...};
extern struct INI myINI;

But i guess you use C++, and i also guess your error is somewhere else... can you post the compiler output and the offending lines?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this