| The compiler complains that I cannot cast the template type as the specific type of cast I am requesting (I am assuming because it is unaware of there relationship). |
No, that's not right. The compiler can see the compile-time types of all the objects involved because they're deducible from the point of use of the template. If the compiler is complaining that the dynamic_cast is not possible, that means you're casting between unrelated types. E.g. dynamic_cast<Iguana *>(mammal) is a cast between unrelated types, because no Mammal * can ever point to an Iguana.
If you're getting this kind of error, either there's a serious design flaw in your code, or you're trying to fetch a given datum from the wrong part of the object.
| The mItemCollection is cast as an array of QGraphicsItem because that is the base class and the IPlotLinkedItem is just an interface that the resulting object also inherits from. |
So you're saying that the compile-time type of the pointer is A, the run-time type of the object is B, and B is a subclass of both A and C, where C is not a subclass of A, and you're trying to perform this cast:
1 2
|
A *a = /*...*/;
C *c = dynamic_cast<C *>(a);
|
That's a cast between unrelated types. dynamic_cast<T1 *>(T2) can only cast pointers where there is an inheritance path from T2 (base) to T1 (derived).
This is like having a pointer to an Equine and trying to cast it to a pointer to a Bird, because you happen to know that the particular object is a Pegasus. dynamic_cast will never let you do that.