2

Here is my scenario:

class Container {};

class Papa {};

class Child: public Papa {};

void myFunction(Container<Papa> container);

Now I want to pass two different parameters to myFunction().

int main() 
{
    Container<Papa> papaContainer;
    Container<Child> childContainer;
    myFunction(papaContainer);
    myFunction(childContainer);  // this line is not working 
}

apparently I cannot do this.

no suitable user-defined conversion from "Container<Child>" to "Container<Papa>"

What would be the solution for this case? How Container<Papa> can be used as interface here?

cigien
  • 57,834
  • 11
  • 73
  • 112
Aryan Firouzian
  • 1,940
  • 5
  • 27
  • 41

1 Answers1

-1

This seems similar to this question here: No Suitable User Defined Conversion although that one is using numeric types. Is there anything in myFunction, or that myFunction returns that would need to differentiate Child from Papa?