title: Trouble with templates in c++: "Expected primary expression before `>` token"
body: <p>I have the following code in a project I am doing for class. I have been having trouble with the print statement for hours, and I could not find what I needed on the internet.</p>
  <p>Here is my templated class definition:</p>
  <pre><code>template &lt;class T&gt;
  class oset {
      template &lt;class U&gt;
      class node { 
      .....
      };
      .....
  public:
     template &lt;class U&gt;
      class iter {
          node&lt;U&gt; *pos;          // node _before_ the one with this-&gt;operator*
          // constructor is private:
          iter(node&lt;U&gt;* n) : pos(n) { }
      friend class oset&lt;U&gt;; 
      ....
      };
   private:
      iter&lt;T&gt; start;         // initialized in the constructors below
      iter&lt;T&gt; finish;        // initialized in the constructors below
  
   public:
      iter&lt;T&gt; begin() {
          return start;
      }
      iter&lt;T&gt; end() {
          return finish;
      }
  ....
  };
  </code></pre>
  <p>Then the problem I'm having is in print:</p>
  <pre><code>template &lt;class S&gt;
  void print(oset&lt;S&gt;&amp; OS) {
      for (oset&lt;S&gt;::iter&lt;S&gt; i = OS.begin(); i != OS.end(); ++i) { 
          // ^-- error is on previous line
          cout &lt;&lt; *i &lt;&lt; &quot; &quot;;
     }
     cout &lt;&lt; endl;
  }
  </code></pre>
  <p>When I try to compile with g++ I get the following error message:</p>
  <blockquote>
  <p>oset.cc:276: error: expected primary-expression before ‘&gt;’ token</p>
  <p>oset.cc:276: error: ‘i’ was not declared in this scope</p>
  </blockquote>
  <p>The problem is in the commented line.  The '&gt;' token giving problems is the one directly before the first <code>i</code>.  For some reason it does not like the <code>&lt;S&gt;</code>.  If i get rid of the <code>&lt;S&gt;</code> it tells me it expects a ';' before the <code>i</code></p>
  <p>I honestly have no idea what is causing the problem. I am getting very frustrated and any help would be highly appreciated.  Thanks!</p>