[問題] 轉型的問題
程式碼如下,我想問的是,為什麼Test2結果會是CDerived呢?因為const?
還是?謝謝~:D
class CBase
{
public:
virtual void Test() const { cout << "Output from CBase!" << endl; };
};
class CDerived : public CBase
{
public:
virtual void Test() const { cout << "Output from CDerived!" << endl; };
};
void Test1(CBase test)
{
test.Test();
}
void Test2(const CBase& test)
{
test.Test();
}
CDerived oTest;
Test1(oTest);
Test2(oTest);
--
查你IP (づ′▽`)づ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.64.227.34
→
04/28 14:23, , 1F
04/28 14:23, 1F
→
04/28 14:31, , 2F
04/28 14:31, 2F
→
04/28 15:06, , 3F
04/28 15:06, 3F
→
04/28 15:10, , 4F
04/28 15:10, 4F
→
04/28 15:41, , 5F
04/28 15:41, 5F
推
04/28 16:05, , 6F
04/28 16:05, 6F
→
04/28 16:11, , 7F
04/28 16:11, 7F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章