Posts

Showing posts from December 30, 2018

Improvement for std::map double dispatch

Image
5 2 I am trying to do my c++ homework and as a part of it I have to implement a std::map with an int as its key and a value should be a specific void function, which prints some text. I can`t find an answer to what are the correct ways of doing that. This is what I have so far: #include <map> #include <string> #include <iostream> class testClass { public: void testFunc1() { std::cout << "func1n"; } void testFunc2() { std::cout << "func2n"; } }; typedef void(testClass::*runFunc)(void); typedef std::map<int, runFunc> myMapType; int main() { testClass t1; std::map<int, runFunc> myMap; myMap.emplace(1, &testClass::testFunc1); myMap.emplace(2, &testClass::testFunc2); myMapType::const_iterator itr;