ATTEMPT 1 - In "borg.h" I have this function
BORG_Problem BORG_Problem_create(
int numberOfVariables,
int numberOfObjectives,
int numberOfConstraints,
void (*function)(double*, double*, double*)) {
BORG_Validate_positive(numberOfVariables);
BORG_Validate_positive(numberOfObjectives);
BORG_Validate_positive(numberOfConstraints);
BORG_Validate_pointer((void*)function);
BORG_Problem problem = (BORG_Problem)malloc(sizeof(struct BORG_Problem_t));
BORG_Validate_malloc(problem);`enter code here`
I'm building a Windows Form Application in Form1.h
Form1. h includes:
#include "borg.h"
...
namespace MO_TLN_NETWORK_GUI
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Runtime::InteropServices;
public ref class Form1 : public System::Windows::Forms::Form
{
//Click button in Form1
private: System::Void btnRun_Click(System::Object^ sender, System::EventArgs^ e)
{
int invars = 8; //Number of variables
int inobjs = 2; //Number of variables
int inconst = 1; //Number of constraints
BORG_Problem problem = BORG_Problem_create(invars, inobjs, inconst, test_problem);
}
//test_problem function in Form1
private: void test_problem (double *xreal, double *obj, double *constr)
{
...
}
};
}
This retrieves a 1 error in compiling:
1>c:\c\borg\mo_tln_network_gui\Form1.h(497) : error C3867:'MO_TLN_NETWORK_GUI::Form1::test_problem': function call missing argument list; use '&MO_TLN_NETWORK_GUI::Form1::test_problem' to create a pointer to member
ATTEMPT 2 - Then I substitute call to BORG_Problem_create:
BORG_Problem problem = BORG_Problem_create(invars, inobjs, inconst, &MO_TLN_NETWORK_GUI::Form1::test_problem);
But this generates another error:
..error C3374: can't take address of 'MO_TLN_NETWORK_GUI::Form1::test_problem' unless creating delegate instance
ATTEMPT 3 - After some looking to some posts, I tried
//Before namespace MO_TLN_NETWORK_GUI, I inserted:
public delegate void MyDel(double *xreal, double *obj, double *constr);
and to call BORG_Problem_create
Form1 ^a = gcnew Form1; //OK
MyDel ^ DelInst = gcnew MyDel(a, &MO_TLN_NETWORK_GUI::Form1::test_problem); //OK
BORG_Problem problem = BORG_Problem_create(invars, inobjs, inconst, DelInst); //ERROR!!!!!!!!!!!
..error C2664: 'BORG_Problem_create' : cannot convert parameter 4 from 'MyDel ^' to 'void (__cdecl *)(double *,double *,double *)' No user-defined-conversion operator available, or There is no context in which this conversion is possible