看板 Programming 關於我們 聯絡資訊
各位好 我目前寫了一個class.h與.cpp function.h https://www.codepile.net/pile/b5pjo49B function.cpp https://www.codepile.net/pile/Gv6oj1VA compile時遇到問題,錯誤訊息是寫 function.cpp:28:25: error: no matching function for call to 'oj::Cuboid::Cuboid()' Cube::Cube(double length) 如果加上initialize list就正常了 但是我不太懂為什麼 請問可以幫我解答嗎 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.6.190 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1589484151.A.3F1.html
adrianshum: 繼承的情況,子類要怎樣init 裡面父 45.64.243.71 05/15 10:32
adrianshum: 的部份?沒特別告知的話就會當成用父 45.64.243.71 05/15 10:32
adrianshum: 類的 no arg constructor. 因為你父 45.64.243.71 05/15 10:32
adrianshum: 類沒no arg Ctor 所以出錯了。解決方 45.64.243.71 05/15 10:32
adrianshum: 法如你所說在init list 用適當的父類c 45.64.243.71 05/15 10:32
adrianshum: tor就行 45.64.243.71 05/15 10:32
Ori185: 我想請問,Cone或Sphere這些也是繼承3DSha180.217.132.250 05/15 12:56
Ori185: pe來的,怎麼不會有call 3Dshape default180.217.132.250 05/15 12:56
Ori185: constructor然後error的問題呢180.217.132.250 05/15 12:56
Ori185: 可能我問題不是描述的很好,抱歉180.217.132.250 05/15 12:58
destroy1101: Shape 110.30.41.199 05/22 23:54
destroy1101: Shape3D你沒有特別指定constructor 110.30.41.199 05/23 00:01
destroy1101: 所以就是Shape3D() 無參數的 110.30.41.199 05/23 00:01
destroy1101: 子類繼承以後沒有特別指定他就會呼 110.30.41.199 05/23 00:01
destroy1101: 叫default的父類constructor 所以跟 110.30.41.199 05/23 00:01
destroy1101: Shape3D是可以match到的 110.30.41.199 05/23 00:01