title: c++ method returning a different type based on a string
body: <p>I am fighting with the following issue for some time:</p>
  
  <p>I have several data types in my application, and they are used like (very simplified code):</p>
  
  <pre><code>QVector&lt;Function*&gt; Container::getFunctions() {return mFunctions};
  QVector&lt;Procedure*&gt; Container::getProcedures() {return mProcedures};
  ....
  QVector&lt;Function*&gt; mFunctions;
  QVector&lt;Procedure*&gt; mProcedures;
  </code></pre>
  
  <p>Both <code>Function</code> and <code>Procedure</code> are derived from a class <code>ObjectWithUid</code> which has </p>
  
  <pre><code>virtual QString getClassUid() = 0;
  </code></pre>
  
  <p>and both <code>Function</code> and <code>Procedure</code> are implementing the virtual method and each of them is returning the respective class uid (for functions this is <code>"CUID_FUNC"</code> and for procedures this is <code>"CUID_PROC"</code>).</p>
  
  <p>And now, I have a method somewhere else:</p>
  
  <pre><code>template &lt;class T&gt; void showObjectList(const QVector&lt;T*&gt; items)
  {
     // show the list of objects
  }
  </code></pre>
  
  <p>which is used like:</p>
  
  <pre><code>showObjectList(getFunctions());
  </code></pre>
  
  <p>or</p>
  
  <pre><code>showObjectList(getFunctions());
  </code></pre>
  
  <p>and as expected I can show either the functions or procedures.</p>
  
  <p>But now I want to be able to show the list based on the class uid of some object, so I would need code like:</p>
  
  <pre><code>ObjectWithUid* obj = giveMeMyObject();
  
  showObjectList(&lt; a vector to which the object belongs determined based on class UID &gt;)
  </code></pre>
  
  <p><em>And here the problems start</em></p>
  
  <p>I wrote the following method:</p>
  
  <pre><code>template &lt;class T&gt; QVector&lt;T*&gt; getListOfObjectsForUid(const QString&amp; uid)
  {
      if(uid == uidFunction)
      {
          return getFunctions();
      }
  
      return QVector&lt;T*&gt;();
  }
  </code></pre>
  
  <p>and I'm trying to use it like:</p>
  
  <pre><code>ObjectWithUid* obj = giveMeMyObject();
  
  showObjectList(getListOfObjectsForUid(obj-&gt;getClassUid()));
  </code></pre>
  
  <p>and the compiler yells: <code>error: no matching function for call to getListOfObjectsForUid(const QString&amp;) candidate is template &lt;class T&gt; QVector&lt;T*&gt; getListOfObjectsForUid(const QString&amp; uid)</code></p>
  
  <p>How can I achieve what I'm looking for? IE: return a vector of different objects based on a string property in a way that I can use it automatically without having to specify the type...</p>