-4
的我有2類A和B和B繼承甲傳遞數型長以構造
class A
{
public:
A(unsigned long seconds = 0) : time(seconds)
{
}
unsigned long GetValue() const
{
return time;
}
private:
unsigned long time;
};
class B : public A
{
public:
B(unsigned long time1 =0):A(time1)
{
}
};
在創建對象B X(3)和I打印x的值與該操作者:
ostream& operator<<(ostream& out,const B& x)
{
out<<(const A&)out<<" "<<x.getName()<<endl;
return out;
}
我得到了巨大的價值。< <運營商實現和工作在A類
你能告訴我們你創建'B x(3)'的代碼,並調用'GetValue()'嗎? – Frank
'(const A&)out'這裏有什麼意思?你的代碼甚至沒有編譯。 – Raindrop7