. Advertisement .
..3..
. Advertisement .
..4..
I have the following cpp code, but I do not know how to find the correct result. Why has this problem occurred, and how can it be solved? Here is the code that I am running:
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;
}
And this is the error text I receive:
Expression preceding parentheses of apparent call must have (pointer-to-) function type
The cause: The issue “expression preceding parentheses of apparent call must have (pointer-to-) function type” shows that
max()
was being called while it was not specified as a function.Solution: Put the parenthesis after the identifier max rather than after the keyword const: Change:
into:
This could also be due to a redefinition or change in a property name or method. A property or method could have the same name.