看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Linux 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) g++ 7.3.0 記得以前這樣能編譯過 , 是因為新版編譯器問題嘛? 想在建構函數把this指標 assign 到 static 變數存放instance https://gist.github.com/shihyu/9ef5b9a30e5221350fc1cbde00205627 可是現在無法編譯過, 想請問一下這是什麼原因? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 106.104.121.78 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1537972718.A.FD8.html
thefattiger: A跟main之間加一行 09/26 23:23
thefattiger: A* A::m_gA = nullptr; 09/26 23:23
thefattiger: 宣告之後還要定義才不會link error 09/26 23:24
yshihyu: 可以了感謝~ 在請教一下m_staticA 為什麼不需要定義 09/26 23:41
yshihyu: 也能正常編譯過? 但是static A* m_gA; 必須要定義? 09/26 23:42
thefattiger: 因為你沒用到,有用到的話也是會link error 09/26 23:47
yshihyu: 了解 感謝 09/27 00:05
tinlans: 要練習看錯誤訊息跟瞭解錯誤訊息 09/28 13:34