CAN extern VARIABLES BE CLASS TYPES?

I have a class "userInterface.h" which I have declare an instance for as a global variable in the main() function and I have also created a header file externVariable.h where I have included the instance of userInterface declare in the main() as a global variable. The intention here is to access the user interface almost anywhere in my program by just including the header file externVariable.h but I'm getting an error "userInterface does not name a type" when I run the program. Thanking you in advance.
Come on guys, i'm sure there is atleast one person out there who can answer my question.
Can you post your code, so we can see what might be wrong with it?

Come on guys, i'm sure there is atleast one person out there who can answer my question.

We're not a paid service, you know. If somebody, out of generosity, chooses to spend their time and energy in helping you with your problem, they'll do it on their own schedule. Trying to badger people into giving you immediate attention is not going to incline people to help you.
Its difficult to understand your problem without some code fragments. Maybe you've included the class/type definition after declaring the variable instead of before?
I have a class "userInterface.h"


Isn't a class it's a header file. Some of your code would be handy so that we could maybe understand what you are getting at.

BTW - complaining that no-one has answered your question within 16 minutes is not very good etiquette is it!
@MikeyBoy sorry if my second posting offended you. Here is my code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <QtGui/QApplication>
#include <QtCore>
#include "uiclass.h"

uiClass userInterface;

int main(int argc, char** argv)
{
    QApplication myApp(argc, argv);


    userInterface.show();

    return myApp.exec();
}


externVariable header file

1
2
3
4
5
6
7
#ifndef EXTERNVAR_H
#define EXTERNVAR_H
#include "uiclass.h"

extern uiClass userInterface;

#endif // EXTERNVAR_H 


and there is a bunch of other .cpp and .h file that are suppose to reference the variable "userInterface".
There is no any problem. Any variable except some rare cases as for example using anonymous unions can have external linkage.

You should declare such a variable in a header with keyword extern and define it in some module outside any function.
@vlad, is the way I did it above wrong? If it is, what do I need to change?
The only problems I can think of are:

1. uiClass might not be complete within uiclass.h

2. There's a naming conflict somewhere within your code (like macros or something)
Topic archived. No new replies allowed.