This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
declaration order of member variables in struct
- From: "Martin Ettl" <ettl dot martin at gmx dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 31 Jul 2009 10:40:58 +0200
- Subject: declaration order of member variables in struct
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