Initialize array with values and size depending on a parameter within the member initializer list of the constructor? C++

28 views Asked by At

I want to initialize an object b, which requires an array a as argument for its constructor. The size and values of a should depend on parameters int d and int v, namely, a = {0, v, 2*v, ..., d*(d-1)*v}.

Restrictions: B does not allow move or copy assignment and does not provide functions for updates.

I would like to do something like this:

class C {
    Array<int> a; 
    B b; 
};

C::C(int d, int v): 
    a({0, v, 2*v, ..., d*(d-1)*v}), 
    b(a){}

What is the best way to do this?

0

There are 0 answers