B
Brian Ross
Hi,
I am trying to do something similar to the following:
int Func1(int x, int y);
double Func2(double x, double y);
template <typename FuncT> // <- What would go here
class CObjectT
{
int f()
{ return FuncT(1, 2); }
};
int main()
{
CObjectT<Func1> Test1;
Test1.f();
CObjectT<Func2> Test2;
Test2.f();
return 0;
}
I am pretty sure that it isn't working because the template parameter needs
to be a type and I am essentially passing a value (of a function). I am also
pretty sure that I can have a function pointer as a parameter but this will
only work if all the functions that will be used as a template parameter
have the same signature - which they wont. I want to be able to have any
function as long as it takes two parameters and returns an 'int'.
Is there any way to do something like the above where I only need to specify
the function as a template parameter and it will compile as long as the code
uses the function correctly?
Thanks
Brian
I am trying to do something similar to the following:
int Func1(int x, int y);
double Func2(double x, double y);
template <typename FuncT> // <- What would go here
class CObjectT
{
int f()
{ return FuncT(1, 2); }
};
int main()
{
CObjectT<Func1> Test1;
Test1.f();
CObjectT<Func2> Test2;
Test2.f();
return 0;
}
I am pretty sure that it isn't working because the template parameter needs
to be a type and I am essentially passing a value (of a function). I am also
pretty sure that I can have a function pointer as a parameter but this will
only work if all the functions that will be used as a template parameter
have the same signature - which they wont. I want to be able to have any
function as long as it takes two parameters and returns an 'int'.
Is there any way to do something like the above where I only need to specify
the function as a template parameter and it will compile as long as the code
uses the function correctly?
Thanks
Brian