给定 gcc-4.8.1 中的以下代码
struct Base
{
};
struct Derive : private Base
{
};
void fn(Base, int);
struct Conv
{
operator Base() const;
operator Derive();
};
int main()
{
Conv c;
fn(c, 0);
return 0;
}
当我给出上面的代码时,我得到了一个错误。我认为编译器会选择Conv::operator Base()
但实际上编译器选择了Conv::operator Derive()
但是当我给出以下代码时,编译器选择了Conv::operator Base()
struct Base
{
};
struct Derive// : private Base
{
};
void fn(Base, int);
struct Conv
{
operator Base() const;
operator Derive();
};
int main()
{
Conv c;
fn(c, 0);
return 0;
}