M
Marcel Sebbao
I want to use a function object for various callbacks, and also as a
normal function.
But this function is a template. It is fine, but then I need to
specify all the time the template
parameter although it is always the same as the constructor argument:
e.g:
template<typename C>
class func {
const C& refClass;
public:
func(const C& aClass) : c(refClass) {}
double operator () (const double& x) const {
return c.(x);
};
};
class myClass {
int a,b;
public:
myClass(const int A, const int B) : a(A), b(B) {}
double ez(const double& x) const {
return pow(cos(x), a) + pow(sin(x), b);
}
};
myClass mc(2,3);
func<myClass> f(mc);
for (int i=0; i<100; ++i)
std::cout << f(i*0.01) << ' ';
std::cout << std::endl;
Well is there any way to declare func such as:
func f(mc) ?
normal function.
But this function is a template. It is fine, but then I need to
specify all the time the template
parameter although it is always the same as the constructor argument:
e.g:
template<typename C>
class func {
const C& refClass;
public:
func(const C& aClass) : c(refClass) {}
double operator () (const double& x) const {
return c.(x);
};
};
class myClass {
int a,b;
public:
myClass(const int A, const int B) : a(A), b(B) {}
double ez(const double& x) const {
return pow(cos(x), a) + pow(sin(x), b);
}
};
myClass mc(2,3);
func<myClass> f(mc);
for (int i=0; i<100; ++i)
std::cout << f(i*0.01) << ' ';
std::cout << std::endl;
Well is there any way to declare func such as:
func f(mc) ?