User LayoutEditorFull Tuesday 24th July 2018
What is the correct method to pass arrays to a user defined function in a macro? The following macro always generates error though it looks fine to me.
```C++
void my_polygon(double p_x[4], double p_y[4])
{
layout->drawing->p(p_x[0], p_y[0]);
layout->drawing->p(p_x[1], p_y[1]);
layout->drawing->p(p_x[2], p_y[2]);
layout->drawing->p(p_x[3], p_y[3]);
layout->drawing->polygon();
}
int main()
{
double ppx[4], ppy[4];
ppx[0]=-10.2; ppx[1]=-2.2; ppx[2]=7.2; ppx[3]=10.6;
ppy[0]=100.2; ppy[1]=22.2; ppy[2]=8.2; ppy[3]=50.6;
layout->drawing->activeLayer=4;
my_polygon(ppx, ppy);
}
```
Jürgen LayoutEditorFull Tuesday 24th July 2018
A double array is identical with a doubleList object. You can use both equivalent and mix the access methods to its members. So this solution would work:
```C++
void my_polygon(doubleList p_x, doubleList p_y)
{
layout->drawing->p(p_x.at(0), p_y.at(0));
layout->drawing->p(p_x.at(1), p_y.at(1));
layout->drawing->p(p_x.at(2),p_y.at(2));
layout->drawing->p(p_x.at(3),p_y.at(3));
layout->drawing->polygon();
}
int main()
{
double ppx[4], ppy[4];
ppx[0]=-10.2; ppx[1]=-2.2; ppx[2]=7.2; ppx[3]=10.6;
ppy[0]=100.2; ppy[1]=22.2; ppy[2]=8.2; ppy[3]=50.6;
layout->drawing->activeLayer=4;
my_polygon(ppx, ppy);
}
```
However the preferred way would be to do it object orientated with the integrated methods:
```C++
pointArray pa;
pa.attach(-10100,100200);
pa.attach(-2200,22200);
pa.attach(7200,8200);
pa.attach(10600,50600);
layout->drawing->currentCell->addPolygon(pa,4);
```