作者Ori185 (JstMonika)
看板Programming
標題[問題] 關於繼承後的constructor
時間Fri May 15 03:22:27 2020
各位好
我目前寫了一個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://webptt.com/m.aspx?n=bbs/Programming/M.1589484151.A.3F1.html
1F:推 adrianshum: 繼承的情況,子類要怎樣init 裡面父 45.64.243.71 05/15 10:32
2F:→ adrianshum: 的部份?沒特別告知的話就會當成用父 45.64.243.71 05/15 10:32
3F:→ adrianshum: 類的 no arg constructor. 因為你父 45.64.243.71 05/15 10:32
4F:→ adrianshum: 類沒no arg Ctor 所以出錯了。解決方 45.64.243.71 05/15 10:32
5F:→ adrianshum: 法如你所說在init list 用適當的父類c 45.64.243.71 05/15 10:32
6F:→ adrianshum: tor就行 45.64.243.71 05/15 10:32
7F:→ Ori185: 我想請問,Cone或Sphere這些也是繼承3DSha180.217.132.250 05/15 12:56
8F:→ Ori185: pe來的,怎麼不會有call 3Dshape default180.217.132.250 05/15 12:56
9F:→ Ori185: constructor然後error的問題呢180.217.132.250 05/15 12:56
10F:→ Ori185: 可能我問題不是描述的很好,抱歉180.217.132.250 05/15 12:58
11F:推 destroy1101: Shape 110.30.41.199 05/22 23:54
12F:→ destroy1101: Shape3D你沒有特別指定constructor 110.30.41.199 05/23 00:01
13F:→ destroy1101: 所以就是Shape3D() 無參數的 110.30.41.199 05/23 00:01
14F:→ destroy1101: 子類繼承以後沒有特別指定他就會呼 110.30.41.199 05/23 00:01
15F:→ destroy1101: 叫default的父類constructor 所以跟 110.30.41.199 05/23 00:01
16F:→ destroy1101: Shape3D是可以match到的 110.30.41.199 05/23 00:01