Avinash
Avinash

Reputation: 13257

std::map and function pointer as the value with different signature

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

Upvotes: 1

Views: 198

Answers (2)

Simon Meister
Simon Meister

Reputation: 126

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.

Upvotes: 0

Paul Manta
Paul Manta

Reputation: 31567

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.

Upvotes: 3

Related Questions