Search code examples
c++stringstring-length

Can the function length() take arguments?


I have experimented with the string length() function to see what can parameters it can take and I get the following error: Q8.cxx:88:17: error: too many arguments to function call, expected 0, have 1

Does this mean this function can never take any arguments? I am curious because it has brackets, (). I want to know if there are some functions in c++ that never take any arguments, but they still have brackets.


Solution

  • "Can the function length() take arguments?" - No.

    If you look it up, you'll see that std::string::length() takes no arguments. So of course you cannot call it with any.

    The brackets () simply mean "call a function". Any arguments go within the brackets. Empty brackets means "call the function with no arguments".

    The name of the function without the brackets means something completely different. It means "pointer to the function", not function call.