Mail Archives: djgpp/1999/08/31/19:40:30
On Mon, 30 Aug 1999 19:11:56 GMT,
remove_this_mimo AT restoel DOT net_and_this (mimo) wrote:
> the other solution - using static member constants - differs from the
> stated aim. defining a constant this way results in having more class
> mebers than before (again think so...), means that static members are
> simply not the same as this precompiler-"trick".
> to make it clear an example:
>
> class c{
> static const int ciSize;
> static const apszString[ciSize];
> };
>
> this simply cannot be done with static members since at the time when
> the precompiler (??) reaches the second const it doesn't know the
> value of ciSize. i am rather sure that this is also the reason for the
> internal compiler error, which could be avoided if it were still
> possible to define consts the way i used to do.
> maybe there is another workaround - thanks in advance.
What you say is a little bit confusing. I assume that you want this:
#include <iostream>
class C {
public:
static const int ciSize=10;
static const char apszString[ciSize];
};
const int C::ciSize; // no initialization here !
const char C::apszString[ciSize]="123456789";
int main() {
cout << c::apszString << endl;
return 0;
}
This is Standard C++ and gcc 2.95 and 2.8.1 do compile it correctly.
Regards
Horst
- Raw text -