0

I have the following code:

class Fruit {};
class Apple : public Fruit {};
class Banana : public Fruit {};

Apple** apples;
Banana** bananas;

void reportAboutFruit(Fruit** fruits);

When I try reportAboutFruit(apples); I get a compiler error, error: invalid conversion from 'Apple**' to 'Fruit**'.

I understand from this question why it would be dangerous to allow reportAboutFruit() to change the data, but as the function name implies I only want to read it, and I only need the stuff contained in the base Fruit class.

I am by no means a C++ expert, can someone explain how I can make this work?

Community
  • 1
  • 1
John
  • 3,430
  • 2
  • 31
  • 44

0 Answers0