question

Mark S3 avatar image
0 Likes"
Mark S3 asked Mark S3 commented

How do I call a custom function from within another custom function?

I defined the Fun1 function.If I want to use Fun1 in Fun2, how do I do it?

qq图片20211231133807.png

FlexSim 21.2.0
dll maker
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Phil BoBo avatar image
3 Likes"
Phil BoBo answered Mark S3 commented

Don't call FLEXSIMINTERFACE functions from another C++ function.

Add a different function with its own signature and call it from both of those functions.

  1. double Fun1_cpp(double a, double b)
  2. {
  3. return a+b;
  4. }
  5.  
  6. visible double Fun1(FLEXSIMINTERFACE)
  7. {
  8. double a = param(1);
  9. double b = param(2);
  10. return Fun1_cpp(a, b);
  11. }
  12.  
  13. visible double Fun2(FLEXSIMINTERFACE)
  14. {
  15. double a = param(1);
  16. double b = param(2);
  17. double c = Fun1_cpp(a, b);
  18. return c;
  19. }

or

  1. double Fun1(double a, double b)
  2. {
  3. return a+b;
  4. }
  5.  
  6. visible double Fun1_FS(FLEXSIMINTERFACE)
  7. {
  8. double a = param(1);
  9. double b = param(2);
  10. return Fun1(a, b);
  11. }
  12.  
  13. visible double Fun2_FS(FLEXSIMINTERFACE)
  14. {
  15. double a = param(1);
  16. double b = param(2);
  17. double c = Fun1(a, b);
  18. return c;
  19. }
· 8
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.