错误:从初始化列表分配到一个数组 [英] Error: Assigning to an array from an initializer list

查看:3211
本文介绍了错误:从初始化列表分配到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,如:

class dialog
{
    public:
    double dReturnType[][5][3];
};

 

#include <cstdlib>
#include <iostream>
include <string>

using namespace std;
#include "dialog.h";

int main(int argc, char *argv[])
{
    dialog People;
    People.dReturnType[0][1] = {1.2,2.3,6.6};
    return 0;
}

返回的是:

[注意]只适用于-std = C ++ 11或延长初始化列表
  -std = gnu11 [默认启用] [错误]:从初始化列表指派给磁盘阵列

[Warning] extended initializer lists only available with -std=c++11 or -std=gnu11 [enabled by default] [Error]: assigning to an array from an initializer list

我看着它在网上了一下,实在无法找到一个方法来解决这个问题。我想preFER不是编辑在它是在类文件中的类(还挺失败的目的)。任何帮助吗?

I've looked it up online a bit and really couldn't find a way to get around this. I'd prefer not editing the class within it's on class file (kinda defeats the purpose). Any help?

注:类是在一个单独的项目文件

Note: the class is in a separate project file

推荐答案

初始化列表的初始化过程中只是使用。

如果你想使用的std :: initializer_list 初始化后:

If you want use std::initializer_list after initialization:

auto init = std::initializer_list<double>({1.2,2.3,6.6});
std::copy(init.begin(), init.end(), your_array);

这篇关于错误:从初始化列表分配到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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