On Thursday, 13 August 2015 at 20:23:56 UTC, Jack Stouffer wrote:
As far as I can tell, there is no way to know the actual type of each of the objects in the list to be able to print:

Cast it to Object first, then do the typeid and it will get the dynamic class type. Since Parent is an interface, typeid works differently.

I wrote about this in more detail recently here:
http://stackoverflow.com/questions/31563999/how-to-get-classinfo-of-object-declared-as-an-interface-type/31564253#31564253

it is a bit of a FAQ, but there's a solid reason behind the behavior.


Also, this fails to compile when it doesn't look like it should:

I believe that's a well-known bug, the array literal tries to type it all to the first element instead of looking for the common types of all elements.

You could explicitly cast to the interface if you needed to, I believe just casting the first one will cause it to do the rest automatically.

Reply via email to