I think he wanted to run a program without having a long list of global variables that may be unnecessary.
i.e.
A program may run 7/10 times without ever calling function two() thus the declaration of the global variable never had to happen.Code:Function one()
{
SomeClass visible_to_all;
}
Function two()
{
AnotherClass visible_to_all;
}
If this is your problem then why not use global pointers? Otherwise the post above this one with global declarations seems fine.
ex: global pointers.
Thus you have global variable declarations that are technically global variables, but aren't really created in memory until a desired function is called in your .lib file. Then you could just extern your pointers in the files that need access to them or include the .lib file that contains the pointer declarations. Would this work for you?Code:int *variable1; // This is a global declaration.
double *variable2; // This is a global declaration.
void functionOne()
{
variable1 = new int[50];
}
void functionTwo()
{
variable2 = new double[50];
}