P
pmatos
Hi all,
I think I'm suffering from some confusion with polymorphic types by
C++.
Imagine the following example:
I have the ABC fruit and then the classes Pear, Apple, Banana that
inherit from fruit. The I create a list of fruits. Now, I wish to
tranverse the list of fruits and now I have op1(banana * b), op2(apple
* a) and op3(pear * p) which should be called for type of fruit. The
problem is that I get an error during compile time since it tells me
op1, op2, and neither op3 receive a fruit*, well, that I understand. I
do not understand is how to solve this issue. What's the best solution?
A cast or something like that?
Cheers,
Paulo Matos
I think I'm suffering from some confusion with polymorphic types by
C++.
Imagine the following example:
I have the ABC fruit and then the classes Pear, Apple, Banana that
inherit from fruit. The I create a list of fruits. Now, I wish to
tranverse the list of fruits and now I have op1(banana * b), op2(apple
* a) and op3(pear * p) which should be called for type of fruit. The
problem is that I get an error during compile time since it tells me
op1, op2, and neither op3 receive a fruit*, well, that I understand. I
do not understand is how to solve this issue. What's the best solution?
A cast or something like that?
Cheers,
Paulo Matos