作者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/cn.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