Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expression preceding parentheses of apparent call must have (pointer-to-) function type

Tags:

c++

c++11

I am learning C++ template on vs2015 community.Here is my code, I want to define a template class and call the member function in the main() function.

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;
}

When I build this program, I get error at the last line. It says:

Expression preceding parentheses of apparent call must have (pointer-to-) function type

What should I do?

like image 927
S.yao Avatar asked Mar 05 '17 03:03

S.yao


1 Answers

For anyone else this might also be because of redefinition of a method or property name. i.e a property and method might have the same name

like image 169
cmd05 Avatar answered Sep 27 '22 22:09

cmd05