1

I want to store function pointers with different signature in a std::map as a value. Is this possible in C++

2 Answers 2

3

It is possible by using something like Boost.Any or Boost.Variant. Keep in mind, however, that you will have to remember somehow what the signature of the function stored (hidden) inside the boost::any object is, so you can retrieve it.

Sign up to request clarification or add additional context in comments.

Comments

0

You do not even need to use boost. You can simply use a functor( overload () operator) as a base class and inherit from it for every different function you need.

1 Comment

Sure, but it would be easy to change the functions from using a return type to reference parameters. Of course i agree to using boost, if you have no chance to change the functions returntype (3rd party/external functions)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.