<small id='fHg7T'></small><noframes id='fHg7T'>

    <bdo id='fHg7T'></bdo><ul id='fHg7T'></ul>

    1. <legend id='fHg7T'><style id='fHg7T'><dir id='fHg7T'><q id='fHg7T'></q></dir></style></legend>
      <i id='fHg7T'><tr id='fHg7T'><dt id='fHg7T'><q id='fHg7T'><span id='fHg7T'><b id='fHg7T'><form id='fHg7T'><ins id='fHg7T'></ins><ul id='fHg7T'></ul><sub id='fHg7T'></sub></form><legend id='fHg7T'></legend><bdo id='fHg7T'><pre id='fHg7T'><center id='fHg7T'></center></pre></bdo></b><th id='fHg7T'></th></span></q></dt></tr></i><div id='fHg7T'><tfoot id='fHg7T'></tfoot><dl id='fHg7T'><fieldset id='fHg7T'></fieldset></dl></div>

        <tfoot id='fHg7T'></tfoot>
      1. C++ 模板编译错误:“&gt;"标记之前的预期主

        时间:2023-10-05

        1. <legend id='oXR0w'><style id='oXR0w'><dir id='oXR0w'><q id='oXR0w'></q></dir></style></legend>

          <i id='oXR0w'><tr id='oXR0w'><dt id='oXR0w'><q id='oXR0w'><span id='oXR0w'><b id='oXR0w'><form id='oXR0w'><ins id='oXR0w'></ins><ul id='oXR0w'></ul><sub id='oXR0w'></sub></form><legend id='oXR0w'></legend><bdo id='oXR0w'><pre id='oXR0w'><center id='oXR0w'></center></pre></bdo></b><th id='oXR0w'></th></span></q></dt></tr></i><div id='oXR0w'><tfoot id='oXR0w'></tfoot><dl id='oXR0w'><fieldset id='oXR0w'></fieldset></dl></div>

          <tfoot id='oXR0w'></tfoot>
                  <bdo id='oXR0w'></bdo><ul id='oXR0w'></ul>

                  <small id='oXR0w'></small><noframes id='oXR0w'>

                    <tbody id='oXR0w'></tbody>
                  本文介绍了C++ 模板编译错误:“&gt;"标记之前的预期主表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  此代码编译并按预期工作(它在运行时抛出,但没关系):

                  This code compiles and works as expected (it throws at runtime, but never mind):

                  #include <iostream>
                  #include <boost/property_tree/ptree.hpp>
                  
                  void foo(boost::property_tree::ptree &pt) 
                  {
                      std::cout << pt.get<std::string>("path"); // <---
                  }
                  
                  int main()
                  {
                      boost::property_tree::ptree pt;
                      foo(pt);
                      return 0;
                  }
                  

                  但是一旦我添加模板并将 foo 原型更改为

                  But as soon as I add templates and change the foo prototype into

                  template<class ptree>
                  void foo(ptree &pt)
                  

                  我在 GCC 中遇到错误:

                  I get an error in GCC:

                  test_ptree.cpp: In function ‘void foo(ptree&)’:
                  test_ptree.cpp:7: error: expected primary-expression before ‘>’ token
                  

                  但 MSVC++ 没有错误!错误在标记的行 <--- 中.再一次,如果我将问题行更改为

                  but no errors with MSVC++! The error is in the marked line <---. And again, if I change the problem line into

                  --- std::cout << pt.get<std::string>("path"); // <---
                  +++ std::cout << pt.get("path", "default value");
                  

                  错误消失(问题出在显式).

                  the error disappears (the problem is in explicit <std::string>).

                  Boost.PropertyTree 需要 Boost >= 1.41.请帮助我理解并修复此错误.

                  Boost.PropertyTree requires Boost >= 1.41. Please help me to understand and fix this error.

                  参见模板:模板函数不能很好地与类的模板成员函数配合使用——一个类似的流行问题,包含其他好的答案和解释.

                  See Templates: template function not playing well with class’s template member function — a similar popular question containing other good answers and explanations.

                  推荐答案

                  你需要做的:

                  std::cout << pt.template get<std::string>("path");
                  

                  在与 typename 相同的情况下使用 template,除了模板成员而不是类型.

                  Use template in the same situation as typename, except for template members instead of types.

                  (也就是说,由于 pt::get 是模板成员依赖模板参数,你需要告诉编译器它是一个模板.)

                  (That is, since pt::get is a template member dependent on a template parameter, you need to tell the compiler it's a template.)

                  这篇关于C++ 模板编译错误:“&gt;"标记之前的预期主表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:当我在一台机器上开发一个 EXE 并在另一台机器上 下一篇:模块对于 SAFESEH 图像 C++ 不安全

                  相关文章

                  最新文章

                  <tfoot id='TPvMk'></tfoot>

                  <i id='TPvMk'><tr id='TPvMk'><dt id='TPvMk'><q id='TPvMk'><span id='TPvMk'><b id='TPvMk'><form id='TPvMk'><ins id='TPvMk'></ins><ul id='TPvMk'></ul><sub id='TPvMk'></sub></form><legend id='TPvMk'></legend><bdo id='TPvMk'><pre id='TPvMk'><center id='TPvMk'></center></pre></bdo></b><th id='TPvMk'></th></span></q></dt></tr></i><div id='TPvMk'><tfoot id='TPvMk'></tfoot><dl id='TPvMk'><fieldset id='TPvMk'></fieldset></dl></div>
                    <bdo id='TPvMk'></bdo><ul id='TPvMk'></ul>
                      <legend id='TPvMk'><style id='TPvMk'><dir id='TPvMk'><q id='TPvMk'></q></dir></style></legend>

                      <small id='TPvMk'></small><noframes id='TPvMk'>