why the compiler doesn't let me init the b with a ?
The initialization value must be a compile time constant. a is a
variable. Even if you defined a as const short, it is still not a
compile time constant.
<<Remove the del for email>>
"Barry Schwarz" wrote:
Your options for compile time constant initialization goes beyond hard-coded
values: You may initialize it to some macro's value (#define BOOOO_HISSSS)
or a specific enum value. The enum hackonly works for int.
With variables you can of course get around it by simply assigning after
declaring(instead of all-in-one initialization). The real problem rears it's
ugly head when you want to inizialize a const with somevalue based another
const.
Are there any other ways besides setting them to a macro or enum?
i.e.
const int i = 1;
const int j = i + 100 // error C2099
enum Name_Does_Not_Matter
{
bar = 5
};
const int foo = bar + 10 // Success!! foo is initialized to 15
Andy