Dear all,
I have a probkelem with a template function. I have 2 classes: Base and SpecializationClass.
I also have a template function of which i made one instanciation (for SpecializationClass as a template parameter)
I alsop have a pointer of type Base*, it points to a SpecializationClass.
Is there any way to make it use the template function of SpecializationClass when calling it with Base* ?
The way it behaves now it does not compile, because "Base" does not have the attribute "attribute" it needs to compile "Function".
I hope I explained the problem...
greetings
LJS
#include <iostream>
usingnamespace std;
// Base class.
class Base
{
public:
int stuff;
};
// specialization class
class SpecializationClass: public Base
{
public:
int attribute;
};
// definition of a template function
template <class T> T Function(T* argument)
{
cout << argument->attribute;
}
// instanciation of template function for derived class
template SpecializationClass Function(SpecializationClass* argument);
int main()
{
Base* myObject = new SpecializationClass();
Function(myObject); // here I want it to call "Function" with a SpecializationClass type...
// but it calls it with a Base* object.
return 0;
}