How to initialize array of a class which takes parameters for its constructor.

Maybe a stupid question but i couldnt find a way to do that.

If the constructor does not take parameters, then the simple method works fine.
poly * p = new poly[5];

But if it does, then i dont know how to initialize it.

please help!
Thank you.
std::vector<poly> p(5, poly(parameters));
Using C++11 uniform initialization http://www.devx.com/cplus/10MinuteSolution/39896/1954

1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct poly
{
    poly( int a, const char* s ) : arr{ a, a+1, a+2, a+3, a+4 }, str{s} {}
    // ...

    int arr[5] ;
    const std::string str ;
};


int main()
{
    poly* p = new poly[3] { { 0, "zero" }, { 1, "one" }, { 2, "two" } } ;
}

Topic archived. No new replies allowed.