Hi @pagarcia,
There are three different template arrays in openNURBS. This from opennurbs_array.h:
ON_SimpleArray
- This template is more efficient than the ON_ClassArray<>
template, but it should not be used for arrays of classes that require explicit construction, destruction, or copy operators.
ON_ClassArray
- This template is designed to be used with classes that require non-trivial construction or destruction. Any class used with this template must have a robust operator=()
.
ON_ObjectArray
- This array is used to store lists of classes that are derived from ON_Object
. It differs from ON_ClassArray
in that the virtual ON_Object::MemoryRelocate
function is called when growing the dynamic array requires changing the location of the memory buffer used to store the elements in the array.
Given this, you can either do this:
ON_SimpleArray<ON_LineCurve*> lines0;
ON_LineCurve* p0 = new ON_LineCurve(ON_3dPoint(0, 0, 0), ON_3dPoint(0, 0, 1));
ON_LineCurve* p1 = new ON_LineCurve(ON_3dPoint(0, 0, 1), ON_3dPoint(0, 0, 2));
lines0.Append(p0);
lines0.Append(p1);
If you do, then don’t forget to recover the allocated memory.
for (int i = 0; i < lines0.Count(); i++)
{
if (nullptr != lines0[i])
{
delete lines0[i];
lines0[i] = nullptr;
}
}
or you can do this:
ON_ObjectArray<ON_LineCurve> lines1;
ON_LineCurve l0(ON_3dPoint(0, 0, 0), ON_3dPoint(0, 0, 1));
ON_LineCurve l1(ON_3dPoint(0, 0, 1), ON_3dPoint(0, 0, 2));
lines1.Append(l0);
lines1.Append(l1);
Hope this helps.
– Dale