Quote:
|
Originally Posted by Paul
Why not just have a conditional declaration?
if(your condition is meet)
{
int your_var;
}
else
{
int something else;
}
I'm probably misunderstanding you but its still worth a shot.
|
Won't work. The declaration goes out of scope after the if block. There are two methods -
1) You know at compile time which one you want
Code:
#if IWANTVAR1
#define myVar var1
#else
#define myVar var2
#endif
//myVar now refers to var1 or var2, depending on IWANTVAR1 (which MUST be either a constant or expand to a constant)
2) You know at runtime
Code:
int myVar;
if(iWantVar1)
myVar = var1;
else
myVar = var2;
Note that way 2 only works for reading the variable, not writing. If you want something like the aliases, you either must know at compile time or deal with pointers (afaik)
I hope this is what you wanted...