I'm certain that I'm doing something wrong here, but I'm not sure how
to do it right.
Here is the code and the errors I get by uncommenting the individual
lines.
Similar errors happen from Comeau's tryitout, so I think this is not a
gcc bug.
Can anyone help?
----
#include <iostream>
#include <complex>
template <typename T>
class X
{
public:
template <size_t N>
class Y
{
public:
Y()
{
T x(12);
std::cout << "X<T>::Y<" << N << "> created, x= " << x << "\n";
}
};
};
void test1()
{
X<float>::Y<8> a;
X< std::complex<float> >::Y<8> b;
}
template <typename T>
void test2()
{
typedef X<T> Z;
//typedef typename Z::Y<2> Z1; // line 32
//typedef Z::Y<2> Z1; // line 33
//X<T>::Y<2> z1; // line 34
//typename X<T>::Y<2> z1; // line 35
}
int main( int argc, char ** argv )
{
test1();
test2< std::complex<float> >();
}
////////////////////////////////////
g++-4.2 (mac os x xcode 3.1)
with only line 32 uncommented:
g++-4.2 t.cpp -o t
t.cpp: In function 'void test2()':
t.cpp:32: error: non-template 'Y' used as template
t.cpp:32: note: use 'test2()::Z::template Y' to indicate that it is a
template
t.cpp:32: error: declaration does not declare anything
t.cpp: At global scope:
t.cpp:49: error: 'with' does not name a type
//////////////////////////////////////////
with only line 33 uncommented:
g++-4.2 t.cpp -o t
t.cpp: In function 'void test2()':
t.cpp:33: error: non-template 'Y' used as template
t.cpp:33: note: use 'test2()::Z::template Y' to indicate that it is a
template
t.cpp:33: error: too few template-parameter-lists
//////////////////////////////////////////
with only line 34 uncommented:
g++-4.2 t.cpp -o t
t.cpp: In function 'void test2()':
t.cpp:34: error: 'z1' was not declared in this scope
t.cpp: In function 'void test2() [with T = std::complex<float>]':
t.cpp:42: instantiated from here
t.cpp:34: error: dependent-name 'X<T>::Y' is parsed as a non-type, but
instantiation yields a type
t.cpp:34: note: say 'typename X<T>::Y' if a type is meant
//////////////////////////////////////////
with only line 35 uncommented:
g++-4.2 t.cpp -o t
t.cpp: In function 'void test2()':
t.cpp:35: error: non-template 'Y' used as template
t.cpp:35: note: use 'X<T>::template Y' to indicate that it is a
template
t.cpp:35: error: declaration does not declare anything
//////////////////////////////////////////
with no lines uncommented, it compiles just fine and runs:
$ ./t
X<T>::Y<8> created, x= 12
X<T>::Y<8> created, x= (12,0)
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|