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

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

      1. <small id='e2CqQ'></small><noframes id='e2CqQ'>

        C++ 编译时错误:数字常量之前的预期标识符

        时间:2023-09-15
            <bdo id='tA8iY'></bdo><ul id='tA8iY'></ul>
          • <legend id='tA8iY'><style id='tA8iY'><dir id='tA8iY'><q id='tA8iY'></q></dir></style></legend>

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

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

                  <tbody id='tA8iY'></tbody>

                  本文介绍了C++ 编译时错误:数字常量之前的预期标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我读过其他类似的帖子,但我只是不明白我做错了什么.我认为我对向量的声明是正确的.我什至试图声明没有尺寸,但即使这样也不起作用.有什么问题??我的代码是:

                  I have read other similar posts but I just don't understand what I've done wrong. I think my declaration of the vectors is correct. I even tried to declare without size but even that isn't working.What is wrong?? My code is:

                  #include <vector> 
                  #include <string>
                  #include <sstream>
                  #include <fstream>
                  #include <cmath>
                  
                  using namespace std;
                  
                  vector<string> v2(5, "null");
                  vector< vector<string> > v2d2(20,v2);
                  
                  class Attribute //attribute and entropy calculation
                  {
                      vector<string> name(5); //error in these 2 lines
                      vector<int> val(5,0);
                      public:
                      Attribute(){}
                  
                  int total,T,F;
                  
                  };  
                  
                  int main()
                  {  
                  Attribute attributes;
                  return 0;
                  }
                  

                  推荐答案

                  你不能这样做:

                  vector<string> name(5); //error in these 2 lines
                  vector<int> val(5,0);
                  

                  在方法之外的类中.

                  你可以在声明点初始化数据成员,但不能用()括号:

                  You can initialize the data members at the point of declaration, but not with () brackets:

                  class Foo {
                      vector<string> name = vector<string>(5);
                      vector<int> val{vector<int>(5,0)};
                  };
                  

                  在 C++11 之前,您需要先声明它们,然后初始化它们,例如在构造函数中

                  Before C++11, you need to declare them first, then initialize them e.g in a contructor

                  class Foo {
                      vector<string> name;
                      vector<int> val;
                   public:
                    Foo() : name(5), val(5,0) {}
                  };
                  

                  这篇关于C++ 编译时错误:数字常量之前的预期标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么我更喜欢使用 vector 来 deque 下一篇:为什么我不能在 C++11 中创建一个 lambda 向量(相同

                  相关文章

                  最新文章

                    <bdo id='4hIZZ'></bdo><ul id='4hIZZ'></ul>

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

                    <small id='4hIZZ'></small><noframes id='4hIZZ'>

                    1. <tfoot id='4hIZZ'></tfoot>
                    2. <legend id='4hIZZ'><style id='4hIZZ'><dir id='4hIZZ'><q id='4hIZZ'></q></dir></style></legend>