
"Daniel Wallin" <dalwan01@student.umu.se> wrote in message news:4016A5B7.3010908@student.umu.se...
Jonathan Turkanis wrote:
"Peter Dimov" <pdimov@mmltd.net> wrote in messag:
If pointers to objects and pointers to arrays need different treatment, one can use:
template<class X> void f(S_ptr<X> px); template<class X> void f(S_ptr<X[]> px);
The problem is that you don't always want to have both overloads and in those cases a compiler error is very unhelpful. I can't come up with very good examples, at least not right now. But in general, disabling an overload is far better than failing to compile. Maybe Peter has some use case where this applies?
I almost agree. The reason that disabling overloads is better than forcing compiler errors is that you often want to allow other overloads to match. Here, if you want another overload -- or if someone else want to write one later -- no problem. If you don't, why not? Either (i) the same code works for smart pointers to objects and smart pointers to arrays, in which case there's no problem, or (ii) the code is specific to one case or the other, so a compiler error indicates a misuse of the function, which seems appropriate. Regards, Jonathan