declaration order of member variables in struct

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

 



Hello,

i have following source, that compiles when the order of the declarations is as following:

#include <iostream>
#include <cstring>

template <int N, int Low=1, int Upp=N> struct Root 
{
  static const int  mean = (Low+Upp)/2;
  static const bool down = ((mean*mean)>=N);
  static const int  ret  = Root<N,(down?Low:mean+1),(down?mean:Upp)>::ret;
}; 
template <int N, int Mid> struct Root<N,Mid,Mid>
{static const int ret = Mid;};

int main()
{
	std::cout << Root<10,1,10>::ret << std::endl;
}

But, when i reorder the declaration sequence in struct Root as followed:

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

g++-4.4.1 complains about and prints the following output:

../src/TestRoot.cpp:8: error: ‘down’ was not declared in this scope
../src/TestRoot.cpp:8: error: ‘mean’ was not declared in this scope
../src/TestRoot.cpp:8: error: ‘down’ was not declared in this scope
../src/TestRoot.cpp:8: error: ‘mean’ was not declared in this scope
../src/TestRoot.cpp:8: error: template argument 2 is invalid
../src/TestRoot.cpp:8: error: template argument 3 is invalid

I do not understand why this depends on the order of declaration?
Many thanks in advance.

Best regards

Ettl Martin

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser

[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