I have a subset of the pointer class that looks like this:
template <typename T>
struct Pointer
{
Pointer();
Pointer(T *const x);
Pointer(const Pointer &x);
template <typename t>
Pointer(const Pointer<t> &x);
operator T *() const;
};
The purpose of the last constructor is to allow the Pointersubclass or basically any type that can be implicitly converted to T *. This actual rule applies only in the constructor definition, and the compiler cannot actually understand this only in the declaration. If I omit it and try to pass it Pointer<Sub>to the constructor Pointer<Base>, I get a compilation error, despite the possible path through operator T *().
While he solves the above problem, he creates another. If I have an overloaded function in which one overload takes Pointer<UnrelatedClass>and the other takes Pointer<BaseClass>, and I try to call it with Pointer<SubClass>, I get ambiguity between the two overloads, with the intention, of course, that the last overload will be called.
Any suggestions? (Hope I was clear enough)
source
share