[問題] assignment operator的寫法問題?

作者: school4303 (某爬蟲類)   2017-11-29 18:05:59
開發平台(Platform):
Win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
VS2015
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)

問題(Question):
assignment operator是不是哪裡有問題?
餵入的資料(Input):

預期的正確結果(Expected Output):
b在大括弧結束被deallocate
a在main結束時才被deallocate
錯誤結果(Wrong Output):
a跟b都被deallocate了
程式碼(Code):(請善用置底文網頁, 記得排版)
https://pastebin.com/fGyTPZDT
補充說明(Supplement):
不要用到自己寫的assignment operator就不會被提早deallocate
所以看起來是它的問題 可是為甚麼會這樣子呢
btw. 如果我把A的num上面那行private:去掉
VS會跟我說cout模稜兩可,這又是為甚麼呢?
作者: loveflames (咕啾咕啾魔法陣)   2017-11-29 18:26:00
你不覺得operator=的參數怪怪的嗎詳細訊息是什麼,哪一行的cout

Links booklink

Contact Us: admin [ a t ] ucptt.com