title: Template Constraints C++
body: <p>In C# we can define a generic type that imposes constraints on the types that can be used as the generic parameter. The following example illustrates the usage of generic constraints:</p>
  
  <pre><code>interface IFoo
  {
  }
  
  
  class Foo&lt;T&gt; where T : IFoo
  {
  }
  
  class Bar : IFoo
  {
  }
  
  class Simpson
  {
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          Foo&lt;Bar&gt; a = new Foo&lt;Bar&gt;();
          Foo&lt;Simpson&gt; b = new Foo&lt;Simpson&gt;(); // error CS0309
      }
  }
  </code></pre>
  
  <p>Is there a way we can impose constraints for template parameters in C++.</p>
  
  <hr>
  
  <p>C++0x has native support for this but I am talking about current standard C++.</p>