declaration order of member variables in struct

Michael Eager
Sun Aug 2 18:06:00 GMT 2009

Martin Ettl wrote:
> -------- Original-Nachricht --------
>> Datum: Sun, 02 Aug 2009 09:03:51 -0400
>> Von: John Fine <>
>> An: Michael Eager <>
>> CC: Martin Ettl <>,
>> Betreff: Re: declaration order of member variables in struct
>> I think Martin was asking why the usual exception to pre declaration 
>> doesn't apply.
>> In defining a class or struct, you can normally use symbols before you 
>> declare them.
> Exactly, this was what i was wondering. In definining a class e.g.
> class A
> {
>   public: 
>     A():m(0){}
>   private:
>     double m;
> };
> The member variable m is used before its declaration. But at the example, i wrote in my first mail, this does not work. 
> I would be interested in why does this not work when using templates?

This has nothing to do with templates.  This modified version
of your example fails with the same errors:

const int N = 5;
const int Low = 1;
const int Upp = 2;
struct Root
   static const int  ret  = down?Low:mean+1;
   static const int  mean = (Low+Upp)/2;
   static const bool down = ((mean*mean)>=N);

I'd have to go back to read the C++ Standard, but I believe that
the initializer for 'm' in your constructor is bound to the class.
The variables 'down' and 'mean' in your example, and in the one
without templates, is not bound to the class.

Michael Eager
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

More information about the Gcc-help mailing list