Implementing the CRTP pattern
<p>I'm trying to implement the <a href="https://stackoverflow.com/questions/4173254/what-is-the-curiously-recurring-template-pattern-crtp">CRTP</a> pattern and, while awfully close, can't quite make it work. My use case is that I need to define a bunch of classes to perform lookups in order to validate values. All of these classes do essentially the same thing and differ only in the files from which they build their lookup values. For a given class type, I want to store the lookup info in a static std::set member (since some of these lookup sets are quite large) that is shared amongst all instances of that type. Research on stackoverflow led me to the CRTP pattern as a way to get "static polymorphism" which is exactly what I need. </p>

<p>In the example below, I have a base lookup class (which itself derives from another class, "CDE"). I then define a child class, ICD9, which should build its set values from the file "icd-9.txt." I breadboarded this concept in a simpler file and it works beautifully.</p>

<p>The problem is that, when compiling, I'm getting an unresolved symbol error during linking. Something, I think, having to do with the constructor. I've tried every permutation I can think of on the ICD9 constructor and can't seem to figure it out. Part of the difference between this and my prototype case is that I am now splitting into header and implementation files, and I suspect I'm getting tripped up on syntax. </p>

<p>Please note that I stripped a lot of extra info from these classes for readability; I think what remains is a legit representation of what's going on. </p>

<p>Any help would be greatly appreciated. Thanks.</p>

<p>The linker error:</p>

<pre><code>Error   1   error LNK2019: unresolved external symbol "public: __thiscall LookupCDE&lt;class ICD9&gt;::LookupCDE&lt;class ICD9&gt;(void)" (??0?$LookupCDE@VICD9@@@@QAE@XZ) referenced in function "public: __thiscall ICD9::ICD9(void)" (??0ICD9@@QAE@XZ)
</code></pre>

<p>LookupCDE.h:</p>

<pre><code>#include &lt;set&gt;
#include "CDE.h"

template &lt;class T&gt;
class LookupCDE : public CDE
{
    typedef std::set&lt;string&gt; lookup;

public:
    LookupCDE();

protected:
    static const char* filepath;
    static lookup data;

    string value;

    bool m1(char* s);
    int f1();
};
</code></pre>

<p>LookupCDE.cpp</p>

<pre><code>#include &lt;fstream&gt;
#include "LookupCDE.h"

template&lt;class T&gt;
LookupCDE&lt;T&gt;::LookupCDE()
{
    ifstream file(filepath);
    while (getline(file, line))
        data.emplace(line);
    file.close();
}

template&lt;class T&gt;
bool LookupCDE&lt;T&gt;::m1(char* s)
{
    return data.count() &gt; 0;
}
</code></pre>

<p>ICD9.h</p>

<pre><code>#include "LookupCDE.h"

class ICD9 : public LookupCDE&lt;ICD9&gt;
{
public:
    ICD9();
};
</code></pre>

<p>ICD9.cpp</p>

<pre><code>#include "ICD9.h"

ICD9::ICD9()
{

}

const char* LookupCDE&lt;ICD9&gt;::filepath = "Data/icd-9.txt";
</code></pre>