Reinitializing an array in C++ with braces

342 views Asked by At

I'm in a situation where creating new variables constantly isn't really a good option, as I'd like to avoid creating a new array for every instance of an object. Essentially, I have a 'point' class, and a 'polygon' class whose constructor takes a vector of points. Since each point has to be manually and individually set, since there aren't really mathematical progressions between them, the most line-conservative solution I've come up with is something using a 'MakeVector' function I've found around, to convert straight arrays to vectors.

Namely, to create one polygon, I've got this:

point ps[]={point(-1,-1,-1),point(1,-1,-1),point(1,1,-1),point(-1,1,-1)};
polygon p1(MakeVector(ps));

Even though this particular set of coordinates has a mathematical progression, not all do, as I'm doing some 3D modeling. The following lines are ineffective and throw errors:

ps=new point[]{point(-1,-1,1),point(1,-1,1),point(1,1,1),point(-1,1,1)};

and

ps={point(-1,-1,1),point(1,-1,1),point(1,1,1),point(-1,1,1)};

I've tried a few different things, and I come across no real way to do this quickly. I'd rather not have to put a new line for every value in an array I make. What would be the best way to do this, with hard-coded values?

0

There are 0 answers