F
Fab
All,
I need your help understanding why the following code does *NOT*
compile with G++ (tested with gcc 3.x and 4.1.x):
---------------------------------------------------------------------
template<class T>
class myvector { // Just a simplification of std::vector
class iterator {
T a;
iterator &operator++();
};
iterator &begin();
iterator &end();
};
template<class T>
struct mytype {
T a;
T b;
};
template<class T>
class Foo {
int abc() {
myvector<mytype<T> > foo;
// DOES work:
//for (myvector<mytype<int> >::iterator iter = foo.begin();
iter != foo.end(); ++iter) {
// DOES NOT work:
for (myvector<mytype<T> >::iterator iter = foo.begin(); iter !
= foo.end(); ++iter) {
// ...
}
return 0;
}
};
---------------------------------------------------------------------
In method Foo::abc if I specify int as template argument for mytype,
everything works, but if I want to use T (the template argument of Foo
class), the compiler reports this error:
foo.cpp: In member function 'int Foo<T>::abc()':
foo.cpp:28: error: expected `;' before 'iter'
foo.cpp:28: error: 'iter' was not declared in this scope
I haven't personally testes, but apparently the Microsoft compiler
(Visual Studio 2005) accept that code.
Any help is appreciated!
Thanks,
Fabrizio
I need your help understanding why the following code does *NOT*
compile with G++ (tested with gcc 3.x and 4.1.x):
---------------------------------------------------------------------
template<class T>
class myvector { // Just a simplification of std::vector
class iterator {
T a;
iterator &operator++();
};
iterator &begin();
iterator &end();
};
template<class T>
struct mytype {
T a;
T b;
};
template<class T>
class Foo {
int abc() {
myvector<mytype<T> > foo;
// DOES work:
//for (myvector<mytype<int> >::iterator iter = foo.begin();
iter != foo.end(); ++iter) {
// DOES NOT work:
for (myvector<mytype<T> >::iterator iter = foo.begin(); iter !
= foo.end(); ++iter) {
// ...
}
return 0;
}
};
---------------------------------------------------------------------
In method Foo::abc if I specify int as template argument for mytype,
everything works, but if I want to use T (the template argument of Foo
class), the compiler reports this error:
foo.cpp: In member function 'int Foo<T>::abc()':
foo.cpp:28: error: expected `;' before 'iter'
foo.cpp:28: error: 'iter' was not declared in this scope
I haven't personally testes, but apparently the Microsoft compiler
(Visual Studio 2005) accept that code.
Any help is appreciated!
Thanks,
Fabrizio