Note that there are some explanatory texts on larger screens.

plurals
  1. POc++, stl map of pointers to functions vectors
    primarykey
    data
    text
    <p>i seem to have some problem in creating a structure defined as the topic.</p> <p>My objective is to create a sort of event handler, (it doesn't matter if it's good or bad programming,or if it is not multithread: for the moment is just for practice).</p> <p>My idea is then to create a vector of pointers to functions, and place this vector in a map,where the key is a string.</p> <p>i must be doing something conceptually wrong, because i get some strange errors: My code is as following (errors are at the end):</p> <pre><code>.h file //ptr to function typedef int (*pt2Function)(void*); typedef std::vector&lt;pt2Function&gt; fPtrVector; class eventDispatcher { public: //stuff void addListener(std::string,pt2Function); protected: //stuff std::map&lt;std::string,fPtrVector&gt; _listeners; }; </code></pre> <p>and here is the cpp:</p> <pre><code>.cpp file void eventDispatcher::addListener(std::string eventName ,pt2Function function) { std::map&lt;std::string,fPtrVector&gt;::iterator it; it=this-&gt;_listeners.find(eventName); if(it != this-&gt;_listeners.end()) { //do something } else { std::vector&lt;pt2Function&gt; tmp; tmp.insert(function); // here occurs error 1 this-&gt;_listeners.insert(eventName,tmp); // here occurs error 2 std::cout&lt;&lt;"cnt: "&lt;&lt; this-&gt;_listeners.count(); } </code></pre> <p>}</p> <p>The errors i get are:</p> <pre><code>1) no matching function for call to 'std::vector &lt;int (*)(void*), std::allocator&lt;int (*)(void*)&gt; &gt;::insert(int (*&amp;)(void*))' 2) no matching function for call to 'std::map&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::vector&lt;int (*)(void*), std::allocator&lt;int (*)(void*)&gt; &gt;, std::less&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::vector&lt;int (*)(void*), std::allocator&lt;int (*)(void*)&gt; &gt; &gt; &gt; &gt;::insert(std::string&amp;, std::vector&lt;int (*)(void*), std::allocator&lt;int (*)(void*)&gt; &gt;&amp;)' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload