Methods that you cannot call indirectly in the copy constructor

I was wondering if someone could explain this question to me:

Considering

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

      

Which of the following methods is NEVER implied in position XXX in the following code?

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

      

A. Orange::Orange()

B. Default Constructors for Data Item in Orange Class

C. Fruit::Fruit()

D. Default Constructors for Data Member in Fruit Class

E. A and C

F. A and D

Granted answer the F .

I thought it was a copy constructor and this class Orange

is a child class and Fruit

is a base class.

I wasn't sure why the answer would be A , and thought that the reason for its D is that it Orange

might have data members that it Fruit

doesn't, so you can't use its default constructor.

Any help would be greatly appreciated.

+3


source to share


1 answer


I thought it was a copy constructor ...

This is not true. The copy constructor takes an instance of the same class, this Orange constructor takes a Color instance as an argument

... and this orange class is a child class, and fruit is a base class.

It is right.

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



It is A because Orange's constructor never indirectly calls another Orange constructor.

... and thought that the reason for this is that the orange might have data members that the fruit doesn't, so you can't use its default constructor.

I find this reasoning odd. I don't see how Orange members can affect how Fruit members can be created.

The wording of the question is ambiguous. The constructors of the Fruit members are called inside the Fruit constructor, and since the Fruit constructor is in a marked position, so are its member constructs, at least indirectly. So whether D is an answer in addition to A is up to the technical and interpretation of the question.

+4


source







All Articles