Hi, I'm trying to implement a mechanism which is supposed to select an appropriate overloaded function.
1. There is a base (template if it matters) class "base_class".
2. There are many other classes that inherit from base_class or do not.
Now, I have a function which operates on a pointer to base_class.
Code:
void Foo(base_class<T>* ptr)
{
// do something with ptr
}
void Foo(void* ptr)
{
// do not do anything
}
Now let's define some classes:
Code:
class ClassA : public base_class<T> {
// inherits
};
class ClassB {
// does not inherit
};
ClassA* a;
ClassB* b;
For those, which inherit from base_class, a call to Foo should resolve to Foo(base_class<T>*), but for those which do not, it should resolve to Foo(void*).
void* can be any type, since it is a dummy parameter.
For example:
Code:
Foo(a); // should call Foo(base_class<T>*)
Foo(b); // should call Foo(void*)
My problem is: this code is not working as expected. For some classes compiler chooses the proper overload, but not for the others. I'm using GCC 4.4.0 (having similar results on Borland's 5.6).
I tried many variations of templates, global functions, and structs. No RTTI, ClassB can be any type, including STL and fundamental types.
Any ideas?
Thanks.