If B
is subclass of A
.
And I have in main()
:
B** b = new B*[10];
... // some algorithm that does b[i] = new B(..);
So I have an array of pointers to objects B
.
Then I have a function:
void f(A** foo);
If in main, I do: f(b);
I get a warning, but obviously if I do: f((A**)b);
, I don't.
The (A**)
its a bit nasty. I was wondering if there's a more elegant way in C++ that at least do type checking as dynamic_cast
.
I want foo to sort (only using swaps) arrays of objects of type A or subclass.. so make a generic sorting algorithm. I hope now you understand better my problem.