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

  • <tfoot id='TLJ57'></tfoot>

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

        C++ 模板编译错误:“&gt;"标记之前的预期主表达式

        时间:2023-07-02
        • <legend id='dVTJx'><style id='dVTJx'><dir id='dVTJx'><q id='dVTJx'></q></dir></style></legend>

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

            <bdo id='dVTJx'></bdo><ul id='dVTJx'></ul>
            • <tfoot id='dVTJx'></tfoot>
                <tbody id='dVTJx'></tbody>

                <i id='dVTJx'><tr id='dVTJx'><dt id='dVTJx'><q id='dVTJx'><span id='dVTJx'><b id='dVTJx'><form id='dVTJx'><ins id='dVTJx'></ins><ul id='dVTJx'></ul><sub id='dVTJx'></sub></form><legend id='dVTJx'></legend><bdo id='dVTJx'><pre id='dVTJx'><center id='dVTJx'></center></pre></bdo></b><th id='dVTJx'></th></span></q></dt></tr></i><div id='dVTJx'><tfoot id='dVTJx'></tfoot><dl id='dVTJx'><fieldset id='dVTJx'></fieldset></dl></div>
                1. 本文介绍了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;"标记之前的预期主表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 Win32 API 列出存储在纯资源库 (DLL) 中的消息 ID 和符号名称 下一篇:哪个编译器是对的?需要模板化返回类型之前的“模板"?

                  相关文章

                      <small id='7WgjR'></small><noframes id='7WgjR'>

                      • <bdo id='7WgjR'></bdo><ul id='7WgjR'></ul>
                      <legend id='7WgjR'><style id='7WgjR'><dir id='7WgjR'><q id='7WgjR'></q></dir></style></legend>
                      <tfoot id='7WgjR'></tfoot>

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