Topic: circumventing recursive definition wrt template specialization


Author: stiss@gmx.net (SainTiss)
Date: Fri, 7 Nov 2003 06:36:54 +0000 (UTC)
Raw View
Hi,

If you've got a template class with lots of methods,
and then you've got a type which works with the template,
except for one method...

What you need to do there is specialize the template for your
type. However, this requires you to copy the whole template, and
change the method, which leads to code duplication...
If there's only 1 template parameter, one can specialize the method
instead of the whole class, but with more template parameters,
this is impossible, because partial specialization of a
method isn't allowed...

Therefore, it would be handy to be able to do this:
template<class A, class T> myClass<A,T*> : public myClass<A,T*>

However, the compiler will complain that you're having a
recursive definition, which is illegal...
Obviously, the compiler thinks that myClass<A,T*> is being
defined here, and therefore no other definition exists...
But in this case, myClass<A,T*> is a template specialization,
and therefore there IS another definition, namely the original
template...

So, is there a reason why this isn't possible, or is this just
something that doesn't happen too often, and therefore not worth
extending the standard?

Thanks,

Hans

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]