Here's the thing, mekkatorqu... every function has to have a signature. std::function allows you to bind functions with slightly different signatures so that they could all be called with the same signature.
The problem is.... you are trying to call with multiple different signatures... which is very easy to break.
Even without the parameter issue, there's the return type issue. Again, reiterating a point I made earlier:
1 2 3 4 5 6 7 8
|
special = (int)test2(my_a, my_b); // assuming this works
if(special() == 5) { /*...*/ } // assuming this works
// so we've established that special() returns an int... so...
special = (void)test3("hello"); // even assuming this works...
if(special() == 5) { /*...*/ } // what would this do? If test3 doesn't return anything...
// then what does this call to special() return? It doesn't make any sense logically.
|
What do you want to happen here? Should special just return 0 by default?
This reeks of poor design. boost::any sounds like the only thing that's close to what you want... but again I don't recommend it. I recommend you rethink whatever it is you're trying to do (what
are you trying to do? Like... the big picture... I understand the immediate problem you're asking about... but I don't understand why you think you need to do it. What is all this for?)
also I absolutely dont understand what [my post] means |
You have one object: 'special'. You are trying to treat it as a swiss army knife: One object for everything you need.
This is almost never a good design decision. Aside from having to tackle problems like the one you're describing, it makes the code error prone. Like the points I keep mentioning... even if the syntax allowed what you want to do... it would be very easy to "break" and do something unexpected/undefined.
Rather than trying to cram everything into one object, split it up across several objects.
But again maybe a big picture view would help. I might be able to recommend a better design idea.