A
aaragon
Hi everyone,
I'm trying to provide some external functionality to a class through a
functor object defined by the user. The concept is as follows:
template <class Functor>
class ClassA
{
...
double evaluate(){
Functor functor_;
return functor_();
}
...
};
// defined by the uesr
struct Functor
{
double operator() (){
return 2+2;
}
};
int main(int argc, char *argv[])
{
ClassA<Functor> a;
a.evaluate();
}
The problem that I have is that the functor needs to know what the
ClassA is to work. So I thought that maybe using a templatized functor
may work:
template <class T>
struct Functor
{
double operator() (T t_){
return t_.x() + t_.y();
}
};
This was a good idea except for the fact that now I have no idea of how
the user is going to delacre an object of classA =/
Any ideas????
I'm trying to provide some external functionality to a class through a
functor object defined by the user. The concept is as follows:
template <class Functor>
class ClassA
{
...
double evaluate(){
Functor functor_;
return functor_();
}
...
};
// defined by the uesr
struct Functor
{
double operator() (){
return 2+2;
}
};
int main(int argc, char *argv[])
{
ClassA<Functor> a;
a.evaluate();
}
The problem that I have is that the functor needs to know what the
ClassA is to work. So I thought that maybe using a templatized functor
may work:
template <class T>
struct Functor
{
double operator() (T t_){
return t_.x() + t_.y();
}
};
This was a good idea except for the fact that now I have no idea of how
the user is going to delacre an object of classA =/
Any ideas????