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

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

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

        C++ 模板类型名迭代器

        时间:2023-05-25
        <i id='VS1oA'><tr id='VS1oA'><dt id='VS1oA'><q id='VS1oA'><span id='VS1oA'><b id='VS1oA'><form id='VS1oA'><ins id='VS1oA'></ins><ul id='VS1oA'></ul><sub id='VS1oA'></sub></form><legend id='VS1oA'></legend><bdo id='VS1oA'><pre id='VS1oA'><center id='VS1oA'></center></pre></bdo></b><th id='VS1oA'></th></span></q></dt></tr></i><div id='VS1oA'><tfoot id='VS1oA'></tfoot><dl id='VS1oA'><fieldset id='VS1oA'></fieldset></dl></div>

            <legend id='VS1oA'><style id='VS1oA'><dir id='VS1oA'><q id='VS1oA'></q></dir></style></legend>
              <tbody id='VS1oA'></tbody>

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

                  <bdo id='VS1oA'></bdo><ul id='VS1oA'></ul>
                  <tfoot id='VS1oA'></tfoot>
                • 本文介绍了C++ 模板类型名迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  考虑以下头文件:

                  template <typename T> struct tNode
                  {
                      T Data;                      //the data contained within this node
                      list<tNode<T>*> SubNodes;       //a list of tNodes pointers under this tNode
                  
                      tNode(const T& theData)
                      //PRE:  theData is initialized
                      //POST: this->data == theData and this->SubNodes have an initial capacity
                      //      equal to INIT_CAPACITY, it is set to the head of SubNodes
                      {
                          this->Data = theData;
                          SubNodes(INIT_CAPACITY);   //INIT_CAPACITY is 10
                      }
                  
                  };
                  

                  现在考虑来自另一个文件的一行代码:

                  Now consider a line of code from another file:

                  list<tNode<T>*>::iterator it();  //iterate through the SubNodes
                  

                  编译器给了我这个错误信息:Tree.h:38:17: error: need 'typename' before 'std::list<tNode<T>*>::iterator' 因为 'std::list*>' 是依赖作用域

                  The compiler is giving me this error message: Tree.h:38:17: error: need ‘typename’ before ‘std::list<tNode<T>*>::iterator’ because ‘std::list<tNode<T>*>’ is a dependent scope

                  我不知道为什么编译器会为此对我大喊大叫.

                  I have no idea why the compiler is yelling at me for this.

                  推荐答案

                  list*>::iterator中,你有一个依赖名称,即依赖于模板参数的名称.

                  In list<tNode<T>*>::iterator, you have a dependant name, that is, a name that depends on a template parameter.

                  因此,编译器无法检查 list*>(此时它没有定义),因此它不知道 >list*>::iterator 要么是静态字段,要么是类型.

                  As such, the compiler can't inspect list<tNode<T>*> (it doesn't have its definition at this point) and so it doesn't know whether list<tNode<T>*>::iterator is either a static field or a type.

                  在这种情况下,编译器假定它是一个字段,因此在您的情况下它会产生语法错误.要解决这个问题,只需在声明前放置一个 typename 来告诉编译器它是一个类型:

                  In such a situation, the compiler assumes that it is a field, so in your case it yields a syntax error. To solve the issue, just tell the compiler that it is a type by putting a typename ahead of the declaration:

                  typename list<tNode<T>*>::iterator it
                  

                  这篇关于C++ 模板类型名迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:默认模板参数偏特化 下一篇:使用模板访问 C++ 中超类的受保护成员

                  相关文章

                  最新文章

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

                  1. <tfoot id='xRvEK'></tfoot>
                    • <bdo id='xRvEK'></bdo><ul id='xRvEK'></ul>

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