For example...if you have a class called Computer....its () operator could be appropriately used to start the computer ...
That doesn't mean that the objects of that class are logically functions.

Originally Posted by manasij7479

It would have different functions...as a computer does.
The () operator just represents the action : 'powering on'.

Its unary + operator could also be "appropriately" used to start the computer, and that doesn't mean that objects of that class are logically numeric in some way... once you begin abusing operator overloading, lots of strange names become appropriate

The point is, a function object (functor) is logically a function. If you are overloading operator() for some other purpose, then you are not working with a function object, and we should start asking if the overloaded operator should have been given a more descriptive name, like... start.

EDIT:
In fact, overloading unary operator+ to start the computer is superior to overloading operator() because you can then overload unary operator- to mean shut down and operator~ to mean reboot!

Last edited by laserlight; 12-12-2011 at 03:27 AM.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

The point is, a function object (functor) is logically a function. If you are overloading operator() for some other purpose, then you are not working with a function object, and we should start asking if the overloaded operator should have been given a more descriptive name, like... start.

But a device is also, logically a function; (...here, also having a state-machine as the back-end)
You give a computer some inputs, (interactively or not)...and it produces an unique output...that is my justification for using the () to invoke it.

But a device is also, logically a function; (...here, also having a state-machine as the back-end)
You give a computer some inputs, (interactively or not)...and it produces an unique output...that is my justification for using the () to invoke it.

I don't exactly agree with you, but I must point out that you very nicely contradicted yourself
Refer to:

Originally Posted by manasij7479

For example...if you have a class called Computer....its () operator could be appropriately used to start the computer ...
That doesn't mean that the objects of that class are logically functions.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

In fact, we don't care whether fn is a function or function object, also don't care what fn does. And the user who calls for_each() should give a function or a object which can be applyed through function-call syntax.

Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

The biggest difference between that and Qt's signals and slots system is that in S&S, the object generating the event doesn't need to explicitly call callbacks. The meta objects system does that for the programmer.

All the programmer needs to do is bind slots to signals, and then, when the signal is fired, all connected slots will automatically be "called" (the observer pattern according to Wikipedia).

It avoids having to write a callback functions that just calls a bunch of other callback functions. In the case of Qt, the "callback functions" (slots) can also be (and usually are) member functions, which makes designs simpler.

The biggest difference between that and Qt's signals and slots system is that in S&S, the object generating the event doesn't need to explicitly call callbacks. The meta objects system does that for the programmer.

All the programmer needs to do is bind slots to signals, and then, when the signal is fired, all connected slots will automatically be "called" (the observer pattern according to Wikipedia).

It avoids having to write a callback functions that just calls a bunch of other callback functions. In the case of Qt, the "callback functions" (slots) can also be (and usually are) member functions, which makes designs simpler.

My point was that, you could design it in a way such that you do not have to resort to macros....moc...or whatever that changes the source.