• <small id='2pbat'></small><noframes id='2pbat'>

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

          <bdo id='2pbat'></bdo><ul id='2pbat'></ul>

      2. <tfoot id='2pbat'></tfoot>

        如何将 vector::push_back()` 与结构一起使用?

        时间:2023-09-15
      3. <small id='hWAMv'></small><noframes id='hWAMv'>

        <tfoot id='hWAMv'></tfoot>

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

                  <bdo id='hWAMv'></bdo><ul id='hWAMv'></ul>
                  本文介绍了如何将 vector::push_back()` 与结构一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何将 push_back struct 转化为向量?

                  How can I push_back a struct into a vector?

                  struct point {
                      int x;
                      int y;
                  };
                  
                  std::vector<point> a;
                  
                  a.push_back( ??? );
                  

                  推荐答案

                  point mypoint = {0, 1};
                  a.push_back(mypoint);
                  

                  或者如果你被允许,给 point 一个构造函数,这样你就可以使用一个临时的:

                  Or if you're allowed, give point a constructor, so that you can use a temporary:

                  a.push_back(point(0,1));
                  

                  如果你在一个用struct声明的类中放置一个构造函数,有些人会反对,这使它成为非POD,也许你无法控制point的定义.因此,您可能无法使用此选项.但是,您可以编写一个提供相同便利的函数:

                  Some people will object if you put a constructor in a class declared with struct, and it makes it non-POD, and maybe you aren't in control of the definition of point. So this option might not be available to you. However, you can write a function which provides the same convenience:

                  point make_point(int x, int y) {
                      point mypoint = {x, y};
                      return mypoint;
                  }
                  
                  a.push_back(make_point(0, 1));
                  

                  这篇关于如何将 vector::push_back()` 与结构一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

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

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

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

                          <tbody id='jqbDv'></tbody>

                          <legend id='jqbDv'><style id='jqbDv'><dir id='jqbDv'><q id='jqbDv'></q></dir></style></legend>