What does the C++ error “A pointer to a bound function may only be used to call the function” mean?

Raymond Chen

TL;DR: You got all set to call a member function but forgot to call it.

void oops(std::vector<std::string>& v)
    //         ^^^^^ error: A pointer to a bound function
    //         may only be used to call the function

What you meant was

void oops(std::vector<std::string>& v)
    //              ^^

Here’s how to decode the error message:

A “bound function” is

  • An object, a dot, and a member function name, or
  • A pointer, a -> arrow, and a member function name.

In the above example, it is the v.front.

Once you write v.front, the only thing you can do next is follow up with parentheses to call the member function. If you forget the parentheses, then you get an error from the compiler that’s basically saying, “The only thing you are allowed to do is use parentheses to call the function, but you didn’t do that!”

Usually it’s because you got all set up to the call the function, and then got distracted and forgot to call it.

So call the function. That’s what you wanted to do in the first place. You just forgot to do it.

Bonus chatter: Many years ago, I was buying tickets at a ticket office (back when you bought tickets at a ticket office), and I got so distracted by the process of buying and paying for tickets that I left the counter without my tickets! Fortunately, I had gotten only a few steps away, and the tickets were waiting for me when I turned around and went back.