So I have base class with template function. I want to call that function from derived class with type specified in that derived class. Base class must not know about type, i'm going to provide to the template function, also the definition of template function should not be in the base header file. At the moment my architecture looks as follows:
Base.h
class Base
{
public:
Base();
template<typename T>
void func(T value);
};
Base.cpp
Base::Base()
{
cout << "Base()" << endl;
}
template<typename T>
void Base::func(T value)
{
cout << "Base::func()" << endl;
}
Derived.h
class Derived : public Base
{
public:
Derived();
void callFunc();
};
Derived.cpp
Derived::Derived()
{
cout << "Derived()" << endl;
}
void Derived::callFunc()
{
Base::func(5);
}
template
void Base::func<int>(int value); // line of the error
But I am getting the error: error: explicit instantiation of ‘void Base::func(T) [with T = int]’ but no definition available [-fpermissive]
So how can I resolve this problem?