Casting array of pointers to objects
Posted
by ritmbo
on Stack Overflow
See other posts from Stack Overflow
or by ritmbo
Published on 2010-03-21T05:26:18Z
Indexed on
2010/03/21
5:31 UTC
Read the original article
Hit count: 286
If B is subclass of A.
And I have in main(): B** b = new B*[10]; ... some algorithm that do b[i] = new B(..); ...
So I have an array of pointers to objets 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 dont.
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.
© Stack Overflow or respective owner