* Bring a typename into scope from a templated base class
@ 2008-09-26 2:20 John Fine
2008-09-26 2:32 ` Brian Dessent
0 siblings, 1 reply; 3+ messages in thread
From: John Fine @ 2008-09-26 2:20 UTC (permalink / raw)
To: gcc-help
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bring a typename into scope from a templated base class
2008-09-26 2:20 Bring a typename into scope from a templated base class John Fine
@ 2008-09-26 2:32 ` Brian Dessent
2008-09-26 12:57 ` John Fine
0 siblings, 1 reply; 3+ messages in thread
From: Brian Dessent @ 2008-09-26 2:32 UTC (permalink / raw)
To: John Fine; +Cc: gcc-help
John Fine wrote:
> 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.
I think what you want is:
template<class T>
struct B : A<T> {
typename A<T>::iterator it; };
See also:
<http://gcc.gnu.org/gcc-3.4/changes.html>
<http://kegel.com/gcc/gcc4.html>
Brian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bring a typename into scope from a templated base class
2008-09-26 2:32 ` Brian Dessent
@ 2008-09-26 12:57 ` John Fine
0 siblings, 0 replies; 3+ messages in thread
From: John Fine @ 2008-09-26 12:57 UTC (permalink / raw)
To: gcc-help
Brian Dessent wrote:
> I think what you want is:
>
> template<class T>
> struct B : A<T> {
> typename A<T>::iterator it; };
>
Thankyou, but that misses the point. I'm not trying to fix the trivial
example. I'm trying to fix real code where the change you suggest would
be massive and would make the code unreadable.
Even the typedef method is much better than changing every use of the
type throughout the class.
I wrote the minimal example in the hopes that someone could explain how
to do what I want to do: Bring a typename into scope from a templated
base class
> See also:
> <http://gcc.gnu.org/gcc-3.4/changes.html>
> <http://kegel.com/gcc/gcc4.html>
>
>
I expect somewhere in all the pages those two link to there is some
discussion of this issues. But starting from the top of those two, I
have no idea how to dig down to it. Near misses are easy to find, for
example:
http://womble.decadentplace.org.uk/c++/template-faq.html#base-lookup
My question is sort of a combination of questions 1 and 2 of that faq.
But the answers don't combine.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-26 12:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-26 2:20 Bring a typename into scope from a templated base class John Fine
2008-09-26 2:32 ` Brian Dessent
2008-09-26 12:57 ` John Fine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).