S
Hallo,
Da Du eine Template Klasse gemacht hast, muss auch die Template Klasse spezialisiert werden.
Hier wäre ein Ansatz. Ich habe mir allerdings dei Freiheit genommen nicht mehr von FunctorBase abzuleiten, damits für mich übersichtlicher wird.
#include <iostream>
template <typename _RetT, typename _ParamT, typename _T>
class Functor
{
public:
Functor(_T addr): m_function(addr)
{}
_RetT operator()(_ParamT param) const
{
return m_function(param);
}
private:
_T m_function;
};
template <typename _RetT, typename _T>
class Functor<_RetT, void, _T>
{
public:
Functor(_T addr): m_function(addr)
{}
_RetT operator()() const
{
return m_function();
}
private:
_T m_function;
};
typedef int (*(Func1))(int);
int square(int i)
{
return i*i;
}
typedef void (*(Func2))(int);
void print(int i)
{
std::cout << i << std::endl;
}
typedef void (*(Func3))();
void test()
{
std::cout << "Test" << std::endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
Functor<int, int, Func1> f1(&square);
int q = f1(12);
Functor<void, int, Func2> f2(&print);
f2(q);
Functor<void, void, Func3> f3(&test);
f3();
return 0;
}
Vielleicht hilfts Dir.
Grüsse Simon