title: Casting void *user_data to object
body: <p>how do I cast <code>void *something</code> to an object in standard C++?
  Specifically I want want to cast <code>void *userdata</code>
  to <code>std::map&lt;String, void*&gt;</code></p>
  
  <p>Is this possible? I am trying:</p>
  
  <pre><code>//void *user_data is a parameter of this function (callback)
  std::map &lt;String, void*&gt; user_data_n; //this line is ok
  user_data_n = static_cast&lt;std::map&lt;String, void *&gt;&gt;(*user_data); //I get the errors here.
  </code></pre>
  
  <p>ERRORs:</p>
  
  <pre><code>Spurious '&gt;&gt;' user '&gt;' to terminate a template argument list
  Expected '&gt;' before '(' token
  'void *' is not a pointer-to-object type
  </code></pre>
  
  <p>or is there a better way to carry information about the caller object and some other parameters I can pass to <code>void *user_data</code>?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Ass suggested by @aaa carp I changed <code>&gt;&gt;</code> to <code>&gt; &gt;</code> and the first two errors were solved. The last is strange, Why do I get that kind of message when casting it here and not when putting that object when setting the callback?</p>
  
  <pre><code>std::map&lt;String, void*&gt; user_data_h;
  user_data_h["Object"] = this; //this is a MainController object
  user_data_h["h"] = h; //h was defined as int *h
  createTrackbar("trackbar_H", winName, h, 255, trackbar_handler, &amp;user_data_h);
  </code></pre>
  
  <p>where createTrackbar is defined as:</p>
  
  <pre><code>int createTrackbar( const string&amp; trackbarname, const string&amp; winname,
  int* value, int count, TrackbarCallback onChange, void* userdata);
  </code></pre>
  
  <p><strong>UPDATE2:</strong></p>
  
  <p>doing this solved my problem but following the same approach, why I still get error when trying to cast objects contained in my map object?</p>
  
  <pre><code>void trackbar_handler(int value, void *user_data){
  std::map &lt;String, void*&gt; *user_data_map;
  user_data_map = reinterpret_cast&lt;std::map&lt;String, void *&gt; *&gt;(user_data); //WORKED!! ;)
  
  MainController *controller; //the same class type I put using "this" above
  controller = reinterpret_cast&lt;MainController *&gt;( user_data_map["Object"]); //ERROR here
  
  int *var = reinterpret_cast&lt;int*&gt; (user_data_map["h"]); //ERROR also here
  </code></pre>