bcc32中一个简单数组的初始化器错误太多 [英] Too many initializers error for a simple array in bcc32

查看:212
本文介绍了bcc32中一个简单数组的初始化器错误太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译以下示例

struct S {};

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

bcc32 我得到以下错误:

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

这是bcc32中的错误还是我缺少的东西,上面的例子是无效的C ++?

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

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

Both Clang and GCC compile this example without problems.

推荐答案

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

Borland BDS2006 (and possibly newer versions)

对于 class struct 默认构造函数/析构函数

添加自定义(甚至为空)构造函数/析构函数解决很多问题。尝试:

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() };
    }

我在 BDS2006 它的工作原理(很难在 struct 中没有任何内容),但是你至少可以编译并运行...

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...

我在 BDS2006 中首先检测到此行为...没有真正尝试 BCB6 ,因为它是从开始垃圾,几天后关闭它(我认为最糟糕的< > BCB 甚至跳过 BCB3,4 )(在 BDS2006 之前)所以他们必须改变C ++引擎(不要混淆运行时库!!!)。

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中一个简单数组的初始化器错误太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆