Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To add a bit more to what the posters above me said:</p> <p>You can not have a partially specialized member function in a template class unless the whole class is partially specialized. </p> <p>In other words, if you are OK with the notion of making a partial specialization for the whole DB class if V is a string, you can do something like</p> <pre><code>template&lt;typename K&gt; class DB&lt;K, string&gt;{ //rest of your stuff here } </code></pre> <p>EDIT:</p> <p>With regards to what Joachim Pileborg, here is an alternative that does not require you to reimplement your whole DB Class. I've ommited some details, but the idea should be clear:</p> <pre><code>template&lt;typename K, typename V&gt; class AbstractDb { public: bool Retrieve(const K&amp;, V&amp;) const { std::cout &lt;&lt; "Retrieve for K and V" &lt;&lt; std::endl; return true; }; }; template&lt;typename K, typename V&gt; class Db: public AbstractDb&lt;K, V&gt;{ public: bool SimpleRetrieve(const K&amp;, const V&amp;) const {std::cout &lt;&lt; "Generic Db2 Simple Retrieve" &lt;&lt; std::endl; return true;}; }; template&lt;typename K&gt; class Db&lt;K, std::string&gt; : public AbstractDb&lt;K, std::string&gt;{ public: bool SimpleRetrieve(const K&amp;, const std::string&amp;) const {std::cout &lt;&lt; "SPecialized Db2 Simple Retrieve" &lt;&lt; std::endl; return true;}; }; int main() { Db2&lt;int, int&gt; db; int a = 4, b = 5; db.SimpleRetrieve(a,b); db.Retrieve(a,b); Db2&lt;int, std::string&gt; specdb; std::string str = "abcd"; std::string str2 = "abcd2"; specdb.SimpleRetrieve(a, str); specdb.Retrieve(a, str2); return 0; } </code></pre> <p>The output of that is:</p> <pre><code>Generic Db2 Simple Retrieve Retrieve for K and V SPecialized Db2 Simple Retrieve Retrieve for K and V </code></pre> <p>You would put your functions that need to be specialized in DB, and the ones that don't - in abstract DB.</p>
    singulars
    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.
    1. VO
      singulars
      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