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

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

    • <bdo id='seOAw'></bdo><ul id='seOAw'></ul>

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

    1. bcc32 中的简单数组的初始值设定项过多错误

      Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
        • <bdo id='XSZhI'></bdo><ul id='XSZhI'></ul>
          <tfoot id='XSZhI'></tfoot>
          <legend id='XSZhI'><style id='XSZhI'><dir id='XSZhI'><q id='XSZhI'></q></dir></style></legend>

                <tbody id='XSZhI'></tbody>

            • <small id='XSZhI'></small><noframes id='XSZhI'>

              <i id='XSZhI'><tr id='XSZhI'><dt id='XSZhI'><q id='XSZhI'><span id='XSZhI'><b id='XSZhI'><form id='XSZhI'><ins id='XSZhI'></ins><ul id='XSZhI'></ul><sub id='XSZhI'></sub></form><legend id='XSZhI'></legend><bdo id='XSZhI'><pre id='XSZhI'><center id='XSZhI'></center></pre></bdo></b><th id='XSZhI'></th></span></q></dt></tr></i><div id='XSZhI'><tfoot id='XSZhI'></tfoot><dl id='XSZhI'><fieldset id='XSZhI'></fieldset></dl></div>
                本文介绍了bcc32 中的简单数组的初始值设定项过多错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                编译下面的例子

                struct S {};int main() {S 数组[1] = { S() };}

                使用 bcc32我收到以下错误:

                [bcc32 Error] test.cpp(4): E2225 初始值设定项过多

                这是 bcc32 中的错误还是我遗漏了什么并且上面的示例不是有效的 C++?

                Clang 和 GCC 编译这个例子都没有问题.

                解决方案

                Borland BDS2006(可能还有更新的版本)

                在其 C++ 引擎中,classstruct默认构造函数/析构函数存在一些问题.

                • 有关详细信息,请参阅bds 2006 C 隐藏内存管理器冲突.

                添加自定义(甚至是空的)构造函数/析构函数可以解决许多问题,甚至是您的问题.试试:

                struct S{S(){};S(S& a){};~S(){};S* 运算符 = (const S *a){};//S* operator = (const S &a){};//仅当您有动态分配成员时才使用它};int main(){S 数组[1] = { S() };}

                我在 BDS2006 中尝试了这个,它看起来有效(如果 struct 中没有任何内容,很难判断)但你至少可以编译和运行......

                我首先在 BDS2006 中检测到这种行为......还没有真正尝试过 BCB6,因为它从一开始就是垃圾,几天后就将其关闭(我认为最糟糕的BCB甚至在BCB5中击败了BCB3,4)都很好(在BDS2006之前这是我最喜欢的IDE) 因此他们必须更改 C++ 引擎(不要与运行时库混淆!!!).

                添加甚至空的构造函数析构函数也有帮助.如果您有动态分配,则需要处理粗分配.如果您有嵌套的类/结构,请不要忘记也将这些添加到它们中.

                Compiling the following example

                struct S {};
                
                int main() {
                  S array[1] = { S() };
                }
                

                with bcc32 I get the following error:

                [bcc32 Error] test.cpp(4): E2225 Too many initializers
                

                Is it a bug in bcc32 or am I missing something and the above example is not valid C++?

                Both Clang and GCC compile this example without problems.

                解决方案

                Borland BDS2006 (and possibly newer versions)

                has some issues with default constructor/destructor for class and struct inside its C++ engine.

                • see bds 2006 C hidden memory manager conflicts for more info.

                Adding custom (even empty) constructor/destructor solves many issues even yours. Try:

                struct S
                    {
                    S(){};
                    S(S& a){};
                    ~S(){};
                    S* operator = (const S *a){};
                    //S* operator = (const S &a){}; // use this only if you have dynamic allocation members
                    };
                
                int main()
                    {
                    S array[1] = { S() };
                    }
                

                I tried this in BDS2006 and it looks like it works (hard to tell without anything inside struct) but you can compile and run at least...

                I detect this behavior first in BDS2006 ... haven't really try BCB6 as it was junk from the start and dismiss it after few days (I think the worst BCB ever even beats BCB3,4) in BCB5 was all fine (before BDS2006 was this my favorite IDE) with this so they must have change the C++ engine (do not confuse with runtime libs !!!).

                Adding even empty constructor destructor helps. If you got dynamic allocations you need to handle those of coarse. If you got nested class/struct do not forget to add these also to them too.

                这篇关于bcc32 中的简单数组的初始值设定项过多错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is Type(::x); valid?(是类型(::x);有效的?)
                Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)
                Validate an argument is ARRAY type in c/c++ pre processing macro on compile time(在编译时验证 c/c++ 预处理宏中的参数是否为 ARRAY 类型)

                  1. <small id='6yOIA'></small><noframes id='6yOIA'>

                      <bdo id='6yOIA'></bdo><ul id='6yOIA'></ul>

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