This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Bring a typename into scope from a templated base class
- From: John Fine <johnsfine at verizon dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 25 Sep 2008 22:20:03 -0400
- Subject: Bring a typename into scope from a templated base class
I am porting some code into gcc 4.1.2 from a much more permissive
compiler. I need to bring many names into the scopes of a templated
classes from templated base classes. (In the more permissive compiler
they are in scope without extra effort).
For function names, a "using" declaration seems to work (though I've
only tried a few examples so far).
For typenames, I've seen other code that uses "using typename". But I
can't get that to work and can't understand the C++ standard well enough
to know why it doesn't work.
So here is a minimal example. Put the following in a .cpp file and
compile with -c to see the error. (The compiler can't parse "iterator
it" because it doesn't know that "iterator" is a typename.
template<class T>
struct A {
typedef T* iterator; };
template<class T>
struct B : A<T> {
using typename A<T>::iterator;
// typedef typename A<T>::iterator iterator;
iterator it; };
B<int> x;
Is there a correct way to do what I want "using typename" to do?
If I use the "typedef typename" instead of the "using typename", it
makes this example work, but it doesn't quite mean the same thing. I'll
use that if there isn't a way to make "using typename" work. But I'd
like to first understand the problem.