title: Typechecking protected tagged union
body: <p>I have to build an expression tree and I'm doing that as follows. I have  a Tree that has a root of type <code>TreeNode&lt;Token&gt;*</code> where Token and TreeNode  looks like this: </p>
  
  <pre><code>struct Token {
      enum{
          PLUS, MINUS, NUMBER, VARIABLE, SIN, COS, POW, PRODUCT, DIVIDE, PI
      } type;
  
      union{
  
          char variable;
          double number;
  
      };//union
  
  };
  
  template &lt;class T&gt;
  class TreeNode{
  
      public:
  
          TreeNode();
          ~TreeNode();
          TreeNode&lt;T&gt;* getLeft() const;
          TreeNode&lt;T&gt;* getRight() const;
          void setLeft(TreeNode&lt;T&gt;* node);
          void setRight(TreeNode&lt;T&gt;* node);
          void setInfo(T value);
          T getInfo() const;
  
      protected:
          T info;
          TreeNode&lt;T&gt; *left;
          TreeNode&lt;T&gt; *right;
  
  };
  </code></pre>
  
  <p>My problem is that I have no idea to access the type of the Token since the info is protected. I have tried something like </p>
  
  <pre><code> root-&gt;getInfo().number = cos(root-&gt;getRight()-&gt;getInfo().number);
  </code></pre>
  
  <p>(here I know the root has a right child which has the correct type etc so this should be okay) but this gets me the following error:  </p>
  
  <pre><code>error: using temporary as lvalue [-fpermissive]
  </code></pre>
  
  <p>Please help!</p>