不能在复制构造函数中隐式调用的方法

Methods you cannot implicitly call in a copy constructor

我想知道是否有人可以向我解释这个问题:

Given

class Fruit {...};
class Orange : public Fruit {....};

Which of the following methods are NEVER implicitly called at position XXX in the following code?

Orange::Orange(const Colour &colour) XXX {...}

A. Orange::Orange()

B. Default constructors for data member within class Orange

C. Fruit::Fruit()

D. Default constructors for data member within class fruit

E. A and C

F. A and D

提供的答案是F

我在想这是一个复制构造函数,class Orange 是一个 child class 而 Fruit 是一个基础 class.

我不确定为什么答案会是 A,我认为答案是 D 是因为 Orange 可能有 Fruit 没有的数据成员,因此你不能使用它的默认构造函数。

如有任何帮助,我们将不胜感激。

I was thinking that this is a copy constructor ...

不是。复制构造函数采用相同的实例 class,Orange 的这个构造函数采用 Color 的实例作为参数

... and that orange class is a child class and fruit is a base class..

这是正确的。

I wasn't sure why the answer would be A ...

它是 A,因为 Orange 的构造函数从不隐式调用 Orange 的另一个构造函数。

... and was thinking that the reason it is D is because orange may have data members that fruit doesn't have therefore you cannot use it's default constructor.

我觉得这个推理很奇怪。我看不出 Orange 的成员如何影响 Fruit 的成员的构造方式。

问题的措辞有歧义。 Fruit 成员的构造函数在 Fruit 的构造函数中被调用,并且由于 Fruit 的构造函数位于标记的位置,因此其成员的构造函数也是如此 - 至少是间接的。因此,D 是否是 A 之外的答案取决于技术性以及您如何解释问题。