title: C++ template class and return type as a constraint
body: <p>Sorry for this foolish question, but I'm quite new to C++.</p>
  
  <p>I have a base class called <code>AlertInfoBase</code> in my project. It has some dozens of subclasses. Now I want to have a class template, which will have a method <code>filter()</code>. This method will always return a reference to <code>AlertInfoBase</code>. Here's the code:</p>
  
  <pre><code>template &lt;class T&gt;
  class AlertInfoFilter
  {
  public:
      AlertInfoFilter() { }
      AlertInfoBase &amp; filter(T &amp; alertInfo)
      {
          return alertInfo;
      }
  };
  </code></pre>
  
  <p>As you can see, the method filter just returns the passed parameter. My goal is to create alternate implementations of <code>filter()</code> using template specialization, but this is not my problem/question right now.
  The strange thing I'm facing is that, when I pass an instance of a class to <code>filter()</code>, which is subclassed from <code>AlertInfoBase</code>, everything works as expected. It returns same reference, but when I pass an instance of a class which doesn't implement <code>AlertInfoBase</code>, the project doesn't compile. Actually this is the kind of behavior I want to have, but some clarification why is this happening would be nice. Is the compiler smart enough to guess that I fill the method with incorrect parameter due to return type?</p>
  
  <p>Thanks</p>
  
  <p>P.S. I'm using MinGW compiler.</p>