'Strange error from CBuilder at compile time using dynamic_cast for similar types

Using C++ Builder 5.0

template <class HYPERSPACE>
inline
bool IsAtLeastHYPERSPACE(hyperspace_t **_)

     { return (dynamic_cast<HYPERSPACE **>(_) != 0); }

that produces a compile error E2031 : cannot cast from 'hyperspace_t **' to 'hyperspace_t **'...

So should I assume that C++ cannot cast from a class to the SAME class pointer ? Then, how to check if the class of an object's pointer is an overloaded class ?

Really blocked by that strange error....

Help appreciated... So I could at least compile...



Solution 1:[1]

Oups... I found my mistake :

As the parameter is an array of pointers of a parent class, I cannot cast it to an array of pointers to a derived class, but only cast to a derived class, a specific element of that source array...

So the code became...

template <class HYPERSPACE>
inline
bool IsAtLeastHYPERSPACE(hyperspace_t **_)

     { return (dynamic_cast<HYPERSPACE *>(_[0]) != 0); }

Notice _[0] instead of _ and HYPERSPACE * instead of HYPERSPACE **

That's all folks...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marek R