Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ template compilation error: expected primary-expression before ‘>’ token
    text
    copied!<p>This code compiles and works as expected (it throws at runtime, but never mind):</p> <pre><code>#include &lt;iostream&gt; #include &lt;boost/property_tree/ptree.hpp&gt; void foo(boost::property_tree::ptree &amp;pt) { std::cout &lt;&lt; pt.get&lt;std::string&gt;("path"); // &lt;--- } int main() { boost::property_tree::ptree pt; foo(pt); return 0; } </code></pre> <p>But as soon as I add templates and change the <code>foo</code> prototype into</p> <pre><code>template&lt;class ptree&gt; void foo(ptree &amp;pt) </code></pre> <p>I get an error in GCC:</p> <pre><code>test_ptree.cpp: In function ‘void foo(ptree&amp;)’: test_ptree.cpp:7: error: expected primary-expression before ‘&gt;’ token </code></pre> <p>but no errors with MSVC++! The error is in the marked line <code>&lt;---</code>. And again, if I change the problem line into</p> <pre><code>--- std::cout &lt;&lt; pt.get&lt;std::string&gt;("path"); // &lt;--- +++ std::cout &lt;&lt; pt.get("path", "default value"); </code></pre> <p>the error disappears (the problem is in explicit <code>&lt;std::string&gt;</code>).</p> <p><a href="http://www.boost.org/doc/libs/1_44_0/doc/html/property_tree.html" rel="noreferrer" title="Boost.PropertyTree">Boost.PropertyTree</a> requires Boost >= 1.41. Please help me to understand and fix this error.</p> <hr> <p><strong>See <a href="https://stackoverflow.com/questions/1682844/templates-template-function-not-playing-well-with-classs-template-member-functi">Templates: template function not playing well with class’s template member function</a></strong> — a similar popular question containing other good answers and explanations.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload