title: Template cast operator C++
body: <p>I am trying to make a little wrapper class such as</p>
  
  <pre><code>template &lt;typename T&gt;
  class EdgeTriggeredState
  
  {
  
  public:
      void Tick()
      {
          oldData = newData;
      }
  
      EdgeTriggeredState&amp; operator =(const T&amp; v)
      {
          newData = v;
          return *this;
      }
  
  //  T&amp; operator = (void)
  //  {
  //      return oldData;
  //  }
  
  //  T&amp; operator T()
  //  {
  //      return oldData;
  //  }
  
  private:
      T oldData;
      T newData;
  };
  </code></pre>
  
  <p>Basically I want to be able to directly assign to a variable of type T the value wrapped by the class. I have tried implementing both an assignment (to type T) operator and a cast operator to type T. I am a bit rusty on my C++ as I have been working solely in C. Is there a way to go about implementing this without creating a named getter method?</p>
  
  <p>When I uncomment the first implementation attempt I get error</p>
  
  <blockquote>
    <p>"../EdgeTriggeredState.h:19:21: error: ‘T&amp; EdgeTriggeredState::operator=()’ must take exactly one argument"</p>
  </blockquote>
  
  <p>When I uncomment the second implementation (and comment out the first) I get error:</p>
  
  <blockquote>
    <p>"../EdgeTriggeredState.h:24:16: error: return type specified for ‘operator T’"</p>
  </blockquote>