c++ - Problem with boost::bind, boost::function and boost::factory -


I'm trying to promote without success: promotion :: bound with factory < P> I have 4 arguments (2 strings and 2 ends) with this class's zombus and

  Class Zambas {public: Zambas (const std :: string &, const std :: String & int z1 = 0, int z2 = 0) {if (z1 == z2) {}}};   

In other ways I have the following call

  boost :: function & lt; Zambas * ()> F (Promotion: Tie (boost :: factory & lt; zambas * & gt; (), std :: string (""), std :: string (""), _ 1, _2));   

This fails with the following compiler error:

Bind HP: 382: Error: รข ???? There is no match for operator []? ??? In a [promotion: _by :: storage 3 & lt; A1, A2, Promotion: Arg & lt; I & gt; & Gt; :: A3_ [A1 = boost :: _ bi :: value & lt; Std :: basic_string & lt; Char, std :: char_traits & lt; Char & gt ;, std :: allocator & lt; Char & gt; & Gt; & Gt ;, A2 = Promotion :: _b :: Value & lt; Std :: basic_string & lt; Char, std :: char_traits & lt; Char & gt ;, std :: allocator & lt; Char & gt; & Gt;

Bind function returns to two-argument factor because you have the placeholder values ​​< Code> _1 to force the third and fourth parameters of its constructor. And _2 . However, you are storing results in the zero-logic function objects.

I was told that when you bind a function, even if they have been declared with default values ​​.

I think you have three options:

  1. Call dam instead of actual int placeholders .
  2. Change the declaration of f to indicate that it stores two-logic functions, and then always returns both values ​​when you call it.
  3. For the variable , force the last two parameters. See in Boost. Lambda documentation After that, you can set those variables to the same default values ​​as the constructor declares. To use default values, do nothing else. To specify a non-default value, assign a value to those variables before calling f before calling them.

    The last option will probably make your code difficult to read without much profit, so instead of choosing one of the first two options.

Comments