I want to downcast a base class pointer to a derived class pointer.
I know that dynamic cast is costly so I want to avoid it. In my case, I am fully aware of the actual class the pointer in question points to. Is there a faster way to downcast it than dynamic casting?
I tried to use static_cast but it won't apply here, because there is virtual inheritance in my class hierarchy.
Update:
Thanks for the comments, I now realize that those dynamic cast is not likely to be the bottleneck of the whole program so it is almost a waste of time trying to optimize it.
It does seem that this is exactly what virtual methods are for. Appropriate use of virtual methods eliminates most needs of dynamic casting. And it even works with virtual inheritance.
Add a
constoverload, for const-correctness, if needed.