title: Templated assignment operator question
body: <p>I want to make sure that *this != &amp;rhs in the assignment operator. But it won't compile. Any suggestions?</p>
  
  <pre><code>template &lt;typename T&gt;
  class A {
    public:
        A() {
            std::cout &lt;&lt; "Default Constructor" &lt;&lt; std::endl;
        }
  
        A(const T&amp; t) : m_t(t) {
            std::cout &lt;&lt; "Templated Constructor" &lt;&lt; std::endl;
        }
  
        template &lt;typename X&gt;
        A( const A&lt;X&gt;&amp; rhs ) : m_t( (static_cast&lt; A&lt;T&gt; &gt;(rhs)).m_t ) {
              std::cout &lt;&lt; "Copy Constructor" &lt;&lt; std::endl;
        }
  
        template &lt;typename X&gt;
        const A&amp; operator=( A&lt;X&gt;&amp; rhs) {
              std::cout &lt;&lt; "Assignment Operator" &lt;&lt; std::endl;
              if (this != static_cast&lt; A&lt;T&gt;* &gt; (&amp;rhs) )
                  m_t = rhs.get();
              return *this;
        }
  
        T get() { return m_t; }
    private:
        T m_t;
  };
  
  
  class base {};
  class derived : public base {};
  
  
  int main()
  {
      A&lt;base*&gt; test1;
      A&lt;derived*&gt; test2;
      test1 = test2;  
  }
  </code></pre>