title: explicit instantiation ... but no definition available [-fpermissive]
body: <p>I'm trying to construct a template class with a static data member and I get this error message when I try to compile the following code:</p>
  
  <pre><code>|In instantiation of ‘T&lt;int&gt;&amp; T&lt;int&gt;::t’:|
  16|required from here|
  16|error: explicit instantiation of ‘T&lt;int&gt;::t’ but no definition available [-fpermissive]|
  |In instantiation of ‘T&lt;int&gt;&amp; T&lt;int&gt;::t’:|
  16|required from here|
  16|error: explicit instantiation of ‘T&lt;int&gt;::t’ but no definition available [-fpermissive]|
  ||=== Build finished: 2 errors, 4 warnings (0 minutes, 0 seconds) ===|
  </code></pre>
  
  <p>code (distilled to the demonstrate the problem.)</p>
  
  <pre><code>template &lt;class A&gt;
  class T {
  private:
      static T&amp;      t;
  public:
      T&amp;   getT() {return t;}
   };
  
  T&lt;int&gt;  i;
  template T&lt;int&gt;&amp; T&lt;int&gt;::t;
  
  int main()
  {
      i.getT();
  
      return 0;
  }
  </code></pre>
  
  <p>I'm afraid I do not understand what is meant by "no definition available." I thought that "template T&amp; T::t;" would define the static data member.</p>
  
  <p>I'm using GCC on Linux:</p>
  
  <pre><code>hbarta@cypress:~$ c++ --version
  c++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
  Copyright (C) 2013 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>
  
  <p>Thanks for any help!</p>
  
  <p>Edit: The declaration of the static member as a reference was clearly an error and I have corrected that.</p>
  
  <p>Thanks for the several solutions and suggestions for this. I will have to study them and decide which is most appropriate.</p>
  
  <p>FWIW, what I am planning to do is reinvent a singly linked list. The target is an Arduino and with limited resources will be sensitive to code and RAM size. Otherwise I would be more than happy to use STL containers. I am coding a singly linked list and the static data member will be a sentinel, pointing to the head of the list. Last element on the list points to the sentinel. For the first iteration, I started writing this using inheritance but soon found that there was no common code for the various derived classes. (They share similarity in concept but that has not translated to implementation, e.g they had distinct lists and distinct processing so it seemed to me that inheritance was a poor initial choice.) Hopefully this difficulty is not a sign that templates are likewise not a good choice.</p>