You've come here because you've entered "cannot be used as a function" into Google Web. This is the Frequently Given Answer to what you'd probably be asking.
Your compiler is telling you that something "cannot be used as a function", and you've decided to plonk the string into a WWW search engine and see what comes up. Until 2010, you'd have seen a lot of people asking the question, with no answers, and the Frequently Given Answer on how class function members cannot be used as thread functions, which wasn't what you were looking for.
It's a largely unanswered question, because it's one of those "Well, duh!"
momements in programming. You've declared a variable, of some type, in a
C or C++ program, and you've used its name in an expression where you've
applied the function-call operator — ()
— to it.
Well, duh! That makes no sense.
The classic unanswered example, that Google Web used to rank near the top, is code like this:
double det2(double b1, double b2, double b3, double b4); double det3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9) { double det1, det2, det3, det5; det1 = (a1 * det2(a5, a6, a8, a9)); det2 = (a4 * det2(a2, a3, a8, a9)); det3 = (a7 * det2(a2, a3, a5, a6)); det5 = det1 - det2 + det3; return det5; }
As you can see, the questioner uses det2
both as a function
and a variable, expecting the compiler to telepathically figure out what
the programmer really wanted to name each time that xe used the name. But
in the scope of the det3
function body, det2
is
declared as a variable, and that's what it remains until the end of the
block scope. Of course it cannot be used as a function. It's
the name of a variable at that point.
There are many variations on this theme, but they all boil down to the same thing. You've used the name of a variable with the function call operator, possibly because you didn't realize that, syntactically, the code that you were writing was a function call operator. That cannot be done, as the error message says.
Always try believing the error message before hitting the WWW search engines.