kwikius wrote:
>
> Beacause the *parent* class is a template this is not allowed IIRC,
> because someone could specialise the parent class which could cause
> ambiguities. That is the rationale or something like it.
>
> If you have boost you can try the enable_if technique --->
[...]
Thanks, but I don't think changing the class template itself is
justified, as my intended specialization isn't part of the interface,
but only for dealing with implementation details.
What I could do, though, is something like the following:-
[Start C++ here.]
#include <iostream>
template<typename T> class thingy {
public:
template<typename U> T f (const U &) const;
};
namespace {
/* Here's how I can get the kind of specialization I'm after.
*/
// The general case:-
template<typename T, typename U> class thingy_f_implementation {
public:
static T f (const U &x) {
::std::clog << "General." << ::std::endl;
return T(x);
}
};
// The special case:-
template<typename T> class thingy_f_implementation<T, T> {
public:
static T f (const T &x) {
::std::clog << "Special." << ::std::endl;
return x;
}
};
}
template<typename T> template<typename U> T thingy<T>::f
(const U &x) const {
return thingy_f_implementation<T, U>::f(x);
}
/* And just to prove it works:-
*/
int main () {
thingy<int> x;
x.f(float(2.3));
x.f(int(42));
return 0;
}
[End C++ here.]
But I'd rather do it more directly, as indicated in my original post. I
hoped it was just that I'd messed up the syntax, or something. But if,
as you say, it just can't be done that way, then I suppose taking the
scenic route (as above) would have to be it.
But thanks for your suggestion anyway
Simon
--
What happens if I mention Leader Kibo in my .signature?