Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to do the following:

class sig
{
public:

int p_list[4];
}

sig :: sig()
{
p_list[4] = {A, B, C, D};
}

I get an error

missing expression in the constructor.

So how do I initilalise an array?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
183 views
Welcome To Ask or Share your Answers For Others

1 Answer

In C++11 only:

class sig
{
    int p_list[4];
    sig() : p_list { 1, 2, 3, 4 }   {   }
};

Pre-11 it was not possible to initialize arrays other than automatic and static ones at block scope or static ones at namespace scope.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...