Reputation: 176
I have an array which is to be filled using an object like this -
const std::map<Id, std::vector<Data>> *const DataSets[]=
{
&object.data1,
&object.data2,
&object.data3,
&object.data4
};
Condition here is, If object.data1.size() == 0 I dont want to push it into array. in that case I want to fill my array like this -
const std::map<Id, std::vector<Data>> *const DataSets[]=
{
&object.data2,
&object.data3,
&object.data4
};
UPDATE I am using std::vector instead of array now and trying to initialize vector in same as array -
const std::vector<std::map<Id, std::vector<Data>>> *const DataSets
{
&object.data1,
&object.data2,
&object.data3,
&object.data4
};
I am getting error: E0146 too many initializer values. Can't I initialize my vector in this way? If not can anyone please suggest how to do that?
Thanks in advance!
Upvotes: 1
Views: 84
Reputation: 122228
[...] since my further logic depends upon this arraya and the code is long back implemented...thatswhy not using vector
Thats not a good reason for not using a vector. If you ever need a c-array you can still use std::vector::data()
in combination with std::vector::size()
. There is (almost) no good reason to prefer a c-array to a std::vector, even if you need c-arrays in some places.
Upvotes: 1
Reputation: 6393
You don't do that.
Respectively you don't use C style plain arrays if you want to do anything dynamic. You just wrap it in yet another std::vector
because that supports dynamic sizes.
Upvotes: 1