Error: Assigning to an array from an initializer list

后端 未结 2 805
梦毁少年i
梦毁少年i 2020-12-06 10:21

I have a class such as:

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

 

#include 
#incl         


        
相关标签:
2条回答
  • 2020-12-06 11:05

    Initializer lists are just usable during initialization.

    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);
    
    0 讨论(0)
  • 2020-12-06 11:11

    You can't initialize a extended list unless you're on c++11.

    And If I was you a good habit is to use * instead of empty "[]" and allocate memory when you know the size (with new or malloc). dReturn type on your program is a pointer of matices.

    And you're giving a full list to only one member of the vector.

    People.dReturnType[0]={1.2,2.3,6.6};
    

    That makes more sense.

    Try to encapsulate and use/create initializer functions that will help you to do that too. C++ will put all 0 at start, but you can do a function and call:

    dialog People("the_atributes_are_here").
    

    It's a good pratice to make the dReturnType private and use functions to acess it data and insert/modify things. But that is up to you.

    0 讨论(0)
提交回复
热议问题