P
Peng Yu
Hi,
I have the following program. The error line is commented. I want to
call _a's member function 'doit' with the template argument of
function<T>. Would you please what is the correct way to do it?
Thanks,
Peng
#include <iostream>
template <typename T>
struct function {
T operator()() const {
return T();
}
};
template <typename T>
struct A {
template <typename F>
T doit() {
return F()();
}
};
template <typename T>
struct B {
public:
T doit() {
return _a.doit<function<T> >();//error
}
private:
A<T> _a;
};
int main() {
A<double> a;
std::cout << a.doit<function<double> >() << std::endl;
}
I have the following program. The error line is commented. I want to
call _a's member function 'doit' with the template argument of
function<T>. Would you please what is the correct way to do it?
Thanks,
Peng
#include <iostream>
template <typename T>
struct function {
T operator()() const {
return T();
}
};
template <typename T>
struct A {
template <typename F>
T doit() {
return F()();
}
};
template <typename T>
struct B {
public:
T doit() {
return _a.doit<function<T> >();//error
}
private:
A<T> _a;
};
int main() {
A<double> a;
std::cout << a.doit<function<double> >() << std::endl;
}