This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

g++: template member specialization oddity


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]