Re: Problem with template using base class template in GCC
From: Paul (invisiblepaul_at_hotmail.com)
Date: 08/27/04
- Next message: Andrew Parker: "static methods in class syntax"
- Previous message: Stephen Howe: "Re: Difference Between List x; and List x(); , if 'List' is a Class?"
- In reply to: Victor Bazarov: "Re: Problem with template using base class template in GCC"
- Next in thread: Victor Bazarov: "Re: Problem with template using base class template in GCC"
- Reply: Victor Bazarov: "Re: Problem with template using base class template in GCC"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Aug 2004 09:52:11 -0700
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message news:<81yXc.316605$a24.50596@attbi_s03>...
> "Walt Karas" <wkaras@yahoo.com> wrote...
> > The following gives an error in the declaration of the
> > member function x() of the class template Tpl, compiliing
> > with a recent version of GCC under Solaris:
> >
> > class A { };
> > class B { };
> >
> > template <typename Base>
> > class Tpl : protected Base
> > {
> > public:
> > template <typename AOrB>
> > int x(void) { return(baseX<AOrB>()); }
>
> I got it to compile by doing this:
>
> template <typename AOrB>
> inx x() { return this->template baseX<AOrB>(); }
>
> > };
> >
> > class TheBase
> > {
> > public:
> >
> > template<typename AOrB>
> > int baseX(void);
> > };
> >
> > template<>
> > inline int TheBase::baseX<A>(void) { return(1); }
> >
> > template<>
> > inline int TheBase::baseX<B>(void) { return(2); }
> >
> > Tpl<TheBase> aTpl;
> >
> > But if I give 'baseX' a dummy parameter whose type is the type parameter
> > to the template, making explicit naming of the type paramenter in the
> > baseX call unecessary, it does compile:
> >
> > class A { };
> > class B { };
> >
> > template <typename Base>
> > class Tpl : protected Base
> > {
> > public:
> > template <typename AOrB>
> > int x(void) { return(baseX(AOrB())); }
> > };
> >
> > class TheBase
> > {
> > public:
> >
> > template<typename AOrB>
> > int baseX(AOrB aOrB);
> > };
> >
> > template<>
> > inline int TheBase::baseX<A>(A a) { return(1); }
> >
> > template<>
> > inline int TheBase::baseX<B>(B b) { return(2); }
> >
> > Tpl<TheBase> aTpl;
> >
> > Is there some rule in the standard that requires this behavior?
>
> Yes, if the base class depends on the template type, its scope is not
> searched to resolve a dependent name.
>
> > Or is this just a problem with the GCC compiler?
>
> I don't think so. Comeau also rejected the first example.
>
> > Another thing that surprised me was that GCC gives me an error if
> > I put the partial specializations of 'baseX' inside the declaration
> > of the class 'TheBase'.
>
> That's also still prohibited. They are thinking of adding it to the
> next Standard, IIRC.
>
> V
Firstly I'd like to say that it compiles ok with MS 2003 Compiler.
I believe it should compile ok as I can see nothing wrong with the
code.
But the point made about name lookup , I have read too that base
templates are not searched but in this case we have the rules of
inheritance do we not. You could also try to call the base funtion
with fully qualified name which also worked for me but was not
required i.e: theBase::baseX<T>(T b);.
Try making your inheritance public then you should be able to call
baseX directly from instances of Tpl.
I don't think it would be very good if templating a class meant we
lost the inheritance, so I believe it's a fault with your compiler.
And also you are speaking of partial specialization but this is not
partial specialization it's full specialization of member function
baseX. I'm not sure on all the rules but I can define them within the
class and it works fine. And I don't see why you shouldn't be able too
do so. I think member function specializations are generally defined
out of class for clarity though.
HTH Paul
- Next message: Andrew Parker: "static methods in class syntax"
- Previous message: Stephen Howe: "Re: Difference Between List x; and List x(); , if 'List' is a Class?"
- In reply to: Victor Bazarov: "Re: Problem with template using base class template in GCC"
- Next in thread: Victor Bazarov: "Re: Problem with template using base class template in GCC"
- Reply: Victor Bazarov: "Re: Problem with template using base class template in GCC"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|