W
Walt Karas
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>()); }
};
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?
Or is this just a problem with the GCC compiler?
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'.
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>()); }
};
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?
Or is this just a problem with the GCC compiler?
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'.