This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++: template member specialization oddity
- To: egcs-bugs at cygnus dot com
- Subject: g++: template member specialization oddity
- From: Jason Riedy <ejr at cise dot ufl dot edu>
- Date: Sat, 11 Jul 1998 00:26:20 -0400
I was experimenting with template member specialization when I
ran into a bit of an oddity. The following code compiles and
does what I expect when the two instances of ack<> have the
same type, but not when they have different types.
I'm not positive my code's right (think it is), but I'm certain
it either shouldn't compile at all or should compile even when
the ack<> template is instantiated with two different types.
Jason
#include <iostream>
template <class T>
class ack
{
public:
T v;
template <class S>
S get_v(S s) const { return v + s; }
};
template<class T>
template<>
int
ack<T>::get_v(int s) const
{
return v + 1; // ignore s if S == int
}
int
main (void)
{
ack<int> a;
ack<long> b; // change long to int and it'll compile & work...
a.v = 4;
b.v = 4;
cout << "a " << a.get_v(4)
<< " b " << b.get_v(4) << endl;
}