Here is a simplified version of a post I saw on another NG:
struct Base {};
struct Derived: Base {};
struct ConstPtr
{
//operator const Derived * (); // F1
operator const Derived * () const; // F2
private:
operator Derived * (); // F3
//operator Derived * () const; // F4
};
int main()
{
ConstPtr ptr;
const Derived * p3 = ptr;
const Base * p4 = ptr;
}
GCC fails both p3 and p4, for private access.
BCC allows p3 but fails p4 for the same reason.
Now consider the slightly modified version, where F1 and F4 are
un-commented.
GCC allows p3, and gives p4 as ambiguous.
BCC allows p3 but fails p4 for private access.
Can someone give me an detailed explanation, w.r.t the Standard,
of what's going on here? I've spent an hour poring over it and am
no closer to solving it really.
As far as I can see, p3+F2 is a standard conversion followed
by a user-defined conversion (both of "Equal Match" status),
and p3+F3 is a user-defined conversion followed by a standard
conversion (both of "Equal Match" status again), so why is one
preferred to the other?
struct Base {};
struct Derived: Base {};
struct ConstPtr
{
//operator const Derived * (); // F1
operator const Derived * () const; // F2
private:
operator Derived * (); // F3
//operator Derived * () const; // F4
};
int main()
{
ConstPtr ptr;
const Derived * p3 = ptr;
const Base * p4 = ptr;
}
GCC fails both p3 and p4, for private access.
BCC allows p3 but fails p4 for the same reason.
Now consider the slightly modified version, where F1 and F4 are
un-commented.
GCC allows p3, and gives p4 as ambiguous.
BCC allows p3 but fails p4 for private access.
Can someone give me an detailed explanation, w.r.t the Standard,
of what's going on here? I've spent an hour poring over it and am
no closer to solving it really.
As far as I can see, p3+F2 is a standard conversion followed
by a user-defined conversion (both of "Equal Match" status),
and p3+F3 is a user-defined conversion followed by a standard
conversion (both of "Equal Match" status again), so why is one
preferred to the other?
Comment