3

Following on @Xeo's excellent code:

I'm wondering how to template the function's return type, so that instead of interpreting the return through:

std::string* out_opt

it could instead return the appropriate type for a given function.

Also, following on @Xeo's example code, I wondering what the best way to bind member functions that have multiple arguments would be...

func_dict["someFunc"] = stream_function<int(int,int)>( std::bind( &MyClass::functionName, instanceOfMyClass, std::_1, std::_2 ) );

Is this a good approach? Is there any way to do away with needing to explicitly state _1, _2, etc.?

4

1 回答 1

0

如果这是 C++11,为什么不

func_dict["someFunc"] = stream_function<int(int,int)>( 
    [&](int x, int y)
    {
      MyClass::functionName(instanceOfMyClass, x, y);
    });

否则,我认为您总是需要以一种或另一种方式明确说明论点。

于 2012-12-09T14:58:03.303 回答