I have Declarer issues can somebody help?

This topic is 4980 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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 on other sites
Make sure you don't have any other variables or #defines that are called INI. Other than that, as crupp said, the best hint will probably be in the compiler's actual error message.