派生类向基类的自动转换类型只对指针或者引用类型有效???
c++primer上说,派生类向基类的自动转换类型只对指针或者引用类型有效,在派生类类型和基类类型之间不存在这样的转换。
书前面说把派生类的基类部分隐藏起来就能当基类使用了。
而且下面还给了例子,怎么又说在派生类类型和基类类型之间不存在这样的转换
Bulk_quote bulk;//派生类对象
Quote item(bulk);//调用Quote::Quote( const Quote& )构造函数
item = bulk ;//调用Quote::operator = (const Quote& )
下面的代码也没有编译错误啊
程序代码:#include <iostream>
#include <string>
using namespace std;
class Base {
public:
Base() = default;
Base( int x ): a(x){ }
private:
int a;
};
class Derived :public Base {
public:
Derived(int x) : b(x) { }
private:
int b;
};
class Derived2 :public Base {
};
int main( )
{
Derived dObj(3) ;
Base bObj( dObj ) , cObj ;
bObj = dObj ;
cObj = dObj ;
return 0;
}








