我有简单的课
template <typename T>
using ConversionFunction = T(*)(T val);
static int Foo1(int x)
{
return x * x;
}
static double Foo1(double x)
{
return x * x + 1;
}
struct Foo
{
ConversionFunction<double> d;
ConversionFunction<int> i;
ConversionFunction<float> f;
template <typename T>
void assign(){
//??
}
};
是否可以这样写:
Foo f;
f.assign<Foo1>();
和
assign
方法会自动获取指向所有现有的具有Foo1
名称的方法的指针?像这样的东西:
template <typename T>
void assign(){
d = if exist(T for double) ? &(T for double) : nullptr;
i = if exist(T for int) ? &(T for int) : nullptr;
f = if exist(T for float) ? &(T for float) : nullptr;
}