+-

我正在学习vs2015社区的C模板.这是我的代码,我想定义一个模板类并在main()函数中调用成员函数.
template <typename T>
class Arithmetic {
T _a;
T _b;
Arithmetic() {};
public
Arithmetic(T a, T b) :_a(a), _b(b) {};
T max const() { return _a + _b; };
T minus const() { return _a - _b; };
};
int main() {
Arithmetic<int> ar(5,6);
cout << ar.max() << endl;
}
当我构建这个程序时,我在最后一行得到错误.它说:
Expression preceding parentheses of apparent call must have (pointer-to-) function type
我该怎么办?
最佳答案
该错误表示尝试调用未定义为函数的函数max().将const关键字后的括号更改为标识符max之后:
T max const()...
至
T max() const ...
点击查看更多相关文章
转载注明原文:c – 明显调用的括号前面的表达式必须具有(指向 – )函数类型 - 乐贴网