This is enclosed in a for loop:
v[i] = new (&vv[i]) vertex(pts[i],i);
vertex
is a struct
pts
is a point*
v
is a vertex**
vv
is a vertex*
What does the (&vv[i])
part do?
It looks like placement new. It's the same as an ordinary new
statement, but instead of actually allocating memory, it uses memory already available and which is pointed to by the expression inside the parentheses.
In your case it uses the memory in vv[i]
to create the new vertex
object, then returns a pointer to that (i.e. &vv[i]
) and it's assigned to v[i]
.
See e.g. this reference for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With