Templates cannot be virtual error when templating class
<p>I have such abstract class:</p>

<pre><code>template&lt;class V, class K&gt;
class MyAbstractCache {
protected:
    ...
public:
    ...
    virtual size_t getSize() const = 0;
    ...
};
</code></pre>

<p>Then a derived one:</p>

<pre><code>template&lt;class V, class K&gt;
class MyLRUCache : public MyAbstractCache&lt;V, K&gt; {
    ...
public:
    ...
    virtual size_t getSize() const {
        return _key_to_value.size();
    }
</code></pre>

<p>The problem is when I put implementation of <code>getSize()</code> out of class declaration I get the compiler error: templates may not be ‘virtual’.</p>

<pre><code>template&lt;class V, class K&gt;
virtual size_t MyLRUCache&lt;V, K&gt;::getSize() { ... } // compile error :(
</code></pre>

<p>Is there a way to deal with it?</p>