{"id":3759,"date":"2014-03-30T05:22:03","date_gmt":"2014-03-30T05:22:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-define-types-call-functions-based-on-configuration-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:22:03","modified_gmt":"2014-03-30T05:22:03","slug":"c-define-types-call-functions-based-on-configuration-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-define-types-call-functions-based-on-configuration-collection-of-common-programming-errors\/","title":{"rendered":"c++ define types\/call functions based on configuration-Collection of common programming errors"},"content":{"rendered":"<p>You can do this but it requires a lot of preparation and prior knowledge. Basically you&#8217;d need to create function pointers to all your class methods, those methods would have to have the same signature, and you&#8217;d need to hold all of this information in a hashtable. Like this:<\/p>\n<pre><code>class Foo {\npublic:\n    void MyMethod1(int _input);\n    void MyMethod2(int _input);\n    .\n    .\n    .\n    void MyMethodN(int _input);\n};\n\ntypedef (Foo::*foo_func)(int);\nclass Acceptor{\npublic:\n    void Command(Foo &amp;_foo, string _name, int _arg){\n        return _foo.*(m_MappedFunctions[ _name ])(_arg);\n    }\nprivate:\n    unordered_map m_MappedFunctions;\n};\n<\/code><\/pre>\n<p>where you&#8217;ve placed function pointers to all of <code>Foo<\/code>&#8216;s methods in the hashtable. You see? It&#8217;s both inflexible and requires a lot of coordinate between code, configuration file and calling convention.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can do this but it requires a lot of preparation and prior knowledge. Basically you&#8217;d need to create function pointers to all your class methods, those methods would have to have the same signature, and you&#8217;d need to hold all of this information in a hashtable. Like this: class Foo { public: void MyMethod1(int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3759","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3759"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3759\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}