views:

290

answers:

6

Hi,

I was asked about one question I totally had no idea.

What's the another name for function object in C++

1) Actions

2) Predicates

3) Operators

4) Use case.

I am confused about the point the question is supposed to deliver.

I searched online a lot but no clue about that.

+8  A: 

I would have said none of the above, and would have thought the word you're looking for is Functor

Binary Worrier
+8  A: 

I'd say neither (though predicates may be expressed through function objects). A correct synonym would be functor.

Dario
+20  A: 

None of those. The correct term is functor.

A functor that returns a bool is a predicate. A functor that returns a bool and takes one argument is a unary-predicate, a functor that returns a bool and takes two arguments is a binary-predicate etc. Many of the function objects used in the C++ standard library are predicates (function objects used by std::unique, std::map, std::sort etc.) but the two terms are not synonymous.

The other three options are even less relevent to the definition of what a function object is.

If you're after the definition of 'function object', I'd say it's an object that is callable as if it were a function. In C++, that translates to an instance of a type that implements operator().

Joe Gauterin
+3  A: 

"Function object" is a synonym of "functor." You can implement predicate functors, so that's probably the answer the interviewer was fishing for.

It is a totally valueless question, however.

John Dibling
+1  A: 

I would say to the interviewer a function object or functor is none of the four an that the first 3 can be modeled with with a functor.

1) Action

A function object can model an action or event. The function would contain details about how to process the action or attributes of the event. This is similar to may GUI's and callback methods work.

2) Predicate

A predicate is a function that returns a boolean value. Many STL algorithms and containers use predicates. One example is for sorting.

3) Operator

A function object can be used as an operator. Many people only implement the operator() method of a functor. A function object can be used to specialize an operation, such as addition.

4) Use Case

A Use Case is one scenario about how a task or program is used. It is an abstract concept usually used in determining the requirements of a system.

I have no problems letting interviews know they are wrong, either on tests or their verbal questions, as long as I have solid proof to back up my claims.

Thomas Matthews
+3  A: 

The answer to the question is probably expected to be (2), but it's kind of a rubbish question. "Predicates" isn't another word for function objects, because predicates are function objects but function objects aren't predicates unless their return type is bool. And that's ignoring that plain functions are possibly predicates too (not sure what definition the question-setter prefers), but aren't objects.

Q.V:

Which of the following is another word for "wine"?

  1. Beer
  2. Champagne
  3. Drinks
  4. Turtles
Steve Jessop