Hi all,
I have a quick question on the usage of the extern keyword. I'm trying to get a variable to be of global scope, but as it is of a custom type, I'm not sure how to use extern and Google doesn't seem to help me.
I'll provide the following code sample to try and illustrate the point better:
Code:
//In header file included at entry point
namespace custom
{
int myInt;
char myChar;
...
//global variable here
Class4 myVar;
};
#include "class1.h"
#include "class2.h" //calls myInt etc
#include "class3.h"
#include "class4.h"
#include "class5.h"
I've currently been thinking that I could open the namespace after the definition of class 4, but this seems a bit hacky. So really, this is a placement problem for which I thought of extern. Unfortunately, I can't extern myVar as it defaults to type int, and I'm not sure how to extern a class. I've tried this to no avail also:
extern Class4;
extern Class4 myVar;
I was thinking that if I can extern to an atomic type, maybe I just needed to 'tell' the compiler that Class4 was a type.
Is extern the right keyword to use? I know that this code is a bit messy, but I'm hoping that somebody may understand the problem I'm having.
Thanks for your help,
SM