title: How to make a class Non-Inheritable
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/702650/making-a-template-parameter-a-friend">Making a template parameter a friend?</a>  </p>
  </blockquote>
  
  
  
  <p>C++ Faq 23.11 <a href="http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.11" rel="nofollow noreferrer">How can I set up my class so it won't be inherited from?</a>
  lists the following code:</p>
  
  <pre><code>class Fred;
  
  class FredBase {
   private:
     friend class Fred;
     FredBase() { }
  };
  
  class Fred : private virtual FredBase {
  public:
     ...
  };
  </code></pre>
  
  <p>I tried to make a generic template for the same.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  template&lt;typename MAKE_ME_NONINHERITABLE &gt;
  class NonInheritable{
  private:
    NonInheritable(){
    }
    friend  MAKE_ME_NONINHERITABLE;  //&lt;--- error here 
  };
  </code></pre>
  
  <p>This give me an error:</p>
  
  <pre><code>xxx.cpp:11: error: a class-key must be used when declaring a friend
  </code></pre>
  
  <p>So I tried:</p>
  
  <pre><code>template&lt;typename  MAKE_ME_NONINHERITABLE &gt;
  class NonInheritable{
  private:
    NonInheritable(){
    }
    friend class MAKE_ME_NONINHERITABLE; //&lt;--- error here 
  };
  
  class A : virtual public NonInheritable&lt;A&gt;{
  };
  </code></pre>
  
  <p>And I get this error:</p>
  
  <pre><code>xxx.cpp:11: error: using typedef-name `MAKE_ME_NONINHERITABLE' after `class'
  </code></pre>
  
  <p>Is there a way to make this work?</p>