Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. CO"I don't think it is possible to invoke a member of a class that is not defined in the current scope." That's nonsense. Whenever function objects are you rarely ever call a member function of a class that's defined in the current scope. (If you pass a function object to `std::for_each()`, it's `operator()` is called in of that function, but it's certainly not defined in its scope.)
      singulars
    2. CO@sbi - The problem is not with directly calling the operator(), but with calling the foreach. If you have: void MyFunc() {< Define class foo here >} Then you can't refer to 'foo' outside of MyFunc. You have to send it somehow (but of course you know that already). I think using inheritance is a legitimate solution, so no need to vote it down. The "not defined in the current scope" can be rephrased to "doesn't have access from the current scope", in which case it should be transferred from within MyFunc (or main) as a value, either by boost::function of by another means with inheritance.
      singulars
    3. COFair enough; I wasn't sufficiently careful in my wording. My point is that C++ doesn't support true runtime binding, a consequence of which is that you can't invoke something that is completely unknown. There is nothing magic about functors. foo is completely unknown outside of main(). Any solution, be it inheritance or whatever, has to make the essence of foo (its public executable interface) accessible outside of main(), and it has to do so at compile time. COM is perhaps the most elaborate example.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload