title: Avoid implicit casting on templated class methods
body: <p>I'm trying to implement an operator overload for a class such as:</p>
  
  <pre><code>template&lt;class T&gt; class A{
  public:
      T val;
  
      A&lt;T&gt;&amp; operator=(const T&amp; v) {
          this-&gt;val = v;
          return *this;
      }
  }
  </code></pre>
  
  <p>So I can do:</p>
  
  <pre><code>A&lt;bool&gt; obj;
  obj = true; // instead of obj.val = true
  obj = false;
  </code></pre>
  
  <p>This works fine.</p>
  
  <p>However, if I do this:</p>
  
  <pre><code>A&lt;bool&gt; obj;
  obj = 123123; // bool is not a number!
  </code></pre>
  
  <p>It still works! Can I somehow prevent that?</p>
  
  <p>I tried marking the overload <code>explicit</code> like this:</p>
  
  <pre><code>explicit A&lt;T&gt;&amp; operator=(const T&amp; v) { ... }
  </code></pre>
  
  <p>but I get an error:</p>
  
  <pre><code>error C2071: 'A&lt;T&gt;::operator =': illegal storage class
  </code></pre>
  
  <p>Is it even possible to do this?</p>