[問題] 子類別move assignment
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC
問題(Question):
各位大大新年快樂
最近在看c++ move語意,看到子類別的move assignment需要呼叫父類別operator=
不懂為何需要這樣
來源是看了stackoverflow的問題
https://reurl.cc/ld38MA
答案是
Derived &operator=(Derived &&rhs) {
Base::operator=(std::move(rhs));//***
// do the derived part
return *this;
}
想問***這行的用意是什麼??完全想不懂為何要呼叫那個operator=
感謝大大回答
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.81.39 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1609517961.A.9F4.html
→
01/02 00:38,
4年前
, 1F
01/02 00:38, 1F
→
01/02 00:38,
4年前
, 2F
01/02 00:38, 2F
→
01/02 00:38,
4年前
, 3F
01/02 00:38, 3F
→
01/02 00:38,
4年前
, 4F
01/02 00:38, 4F
→
01/02 00:38,
4年前
, 5F
01/02 00:38, 5F
→
01/02 00:38,
4年前
, 6F
01/02 00:38, 6F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章