看板 NTUEE110HW 關於我們 聯絡資訊
小弟有個疑惑 懇請眾高手指點 Derived Class D 以public的方式繼承自 Base Class B 而 B 有提供 copy constructor 但沒有 data member的set function 那我想問的是 若我想寫一個D的 copy constructor D::D( const D & input ) 那我要如何 initialize D 繼承自 B 的 data member 呢 ? 有辦法 把 input 的 B 的部份抽離出來 進而呼叫 B 的copy constructor 嗎? 麻煩大家撥冗幫忙解惑 小弟感激不盡 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.229.232.251
timrau:D::D(const D& input) : B(input.a, input.b) { ... } 01/14 13:03
yehes2001:饒神您好 印象中 derived class不能access base class的 01/14 13:06
yehes2001:private data member耶 01/14 13:07
firstquarter:其實改成protected就好了 01/15 23:42