我基本上想使用一个差异函数来提取一个类(ac)的不同元素。
代码与此类似:
。H:
class MyClass
{
public:
double f1(AnotherClass &);
void MyClass::f0(AnotherClass & ac, double(MyClass::*f1)(AnotherClass &));
};
.cc:
double MyClass::f1(AnotherClass & ac)
{
return ac.value;
}
void MyClass::f0(AnotherClass & ac, double(MyClass::*f1)(AnotherClass &))
{
std::cout << f1(ac);
}
没有用,它给出了错误#547“获取成员函数地址的非标准形式”
编辑:
我从以下位置调用它:
void MyClass(AnotherClass & ac)
{
return f0(ac,&f1); // original and incorrect
return f0(ac,&Myclass::f1); //solved the problem
}
但是,我还有另一个错误:
std::cout << f1(ac);
^ error: expression must have (pointer-to-) function type