3

I found this code on internet :

Class Book{
Public:
void operator()(int Counter) const throw();
}

My question is, what operator overloading the above code used?

1
  • Overloading the parenthesis operator () Commented Dec 31, 2015 at 21:50

2 Answers 2

11

Firstly, that code is wrong; since C++ is case sensitive, Class and Public are not keywords. It is also very unusual (albeit legal) to capitalize the first letter of a parameter name (Counter).

Assuming correct capitalization, what you have is an overload of the function-call operator. It allows you to "call" an instance of Book as if it was a function:

Book b;
...
b(23);
Sign up to request clarification or add additional context in comments.

Comments

2

The above class is basically called a "Functor". It has an overloaded "()" operator. Widely used in STL Algorithms.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.