Quote:Original post by Sync Views
Is there a better way other than template functions or type id's to pass a type and check if that type is the same as the type a pointer is pointing to? Taking into acount inheritance etc?
eg
*** Source Snippet Removed ***
I only really need to check if the item I'm pointing to is either the same as the objtype or a child of it...
Templates are compile-time polymorphism. You need to provide the type you're using.
If you want inheritance and all that, you need run-time polymorphism, where you do not know the type ahead.
Decide which you want. Mixing both is generally not needed, especially not in the way you want.
void * is always bad, except under certain circumstances for internal usage. But in general, you should never (in C++) need this in user API.
Quote:I only really need to check if the item I'm pointing to is either the same as the objtype or a child of it...
Why not imply that?
void foo(BaseType * bar){ // whatever, but bar is of type BaseType};
Here you'd get compile-time check if you pass incorrect instance.
Obviously, bars will come from, for example, std::vector<BaseType *>. C++ provides type safety. Use it.