title: C++ finding type of subclass with a pointer to superclass
body: <p>In my C++ code, I have a vector of pointers to a Light object. P_Light is a subclass of Light, and has a field position. For each pointer pointing to a Light that is actually a P_Light, I need to do something with the position field. I did some searching and it seems like I can implement a virtual method, but I don't need the method in Light since other types of Light don't have a position. I also thought about casting but I'm not sure how to make that work.</p>
  
  <pre><code>std::vector&lt;Vector&gt; light_dirs;
  for(int i=0; i&lt;lights.size; i++){
      Light *l = lights[i];   
      //cast here?
  }
  </code></pre>
  
  <p>EDIT::
  Saw in a different post that maybe using qobject_cast would be a good idea. Does this look better?</p>
  
  <pre><code>std::vector&lt;Vector&gt; light_dirs;
  for(int i=0; i&lt;lights.size; i++){
      Light *l = lights[i];   
      P_Light* pl = qobject_cast&lt;P_Light*&gt;(l);
      if(pl != nullptr) //dostuff;
  }
  </code></pre>