Support Forum

passing arrays to a user defined function

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, double p_y) { layout->drawing->p(p_x, p_y); layout->drawing->p(p_x, p_y); layout->drawing->p(p_x, p_y); layout->drawing->p(p_x, p_y); layout->drawing->polygon(); } int main() { double ppx, ppy; ppx=-10.2; ppx=-2.2; ppx=7.2; ppx=10.6; ppy=100.2; ppy=22.2; ppy=8.2; ppy=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, ppy; ppx=-10.2; ppx=-2.2; ppx=7.2; ppx=10.6; ppy=100.2; ppy=22.2; ppy=8.2; ppy=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); ```