Re: declaration order of member variables in struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Ettl wrote:
-------- Original-Nachricht --------
Datum: Sun, 02 Aug 2009 09:03:51 -0400
Von: John Fine <johnsfine@xxxxxxxxxxx>
An: Michael Eager <eager@xxxxxxxxxxxx>
CC: Martin Ettl <ettl.martin@xxxxxx>, gcc-help@xxxxxxxxxxx
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	 eager@xxxxxxxxxxxx
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux