I am trying to write a class template and internally it use a C
function (implementation of BFGS optimization, provided by the R
environment) with
An alternative solution could be to have the optim
class do its magic with two (possibly pure) virtual functions, and then inherit to define a new class Rosen
which implements them. This could look like
class optim {
public:
// ...
virtual double fn(int n, double *par, void *ex) = 0;
virtual void gr(int n, double *par, double *gr, void *ex) = 0;
void minimize(arma::vec &dpar, void *ex) {
vmmin(... , &fn, &gr, ...);
// ...
}
};
class Rosen : public optim {
public:
// ...
double fn(int n, double *par, void *ex);
void gr(int n, double *par, double *gr, void *ex);
private:
// ...
};
// main.cc
Rosen obj;
obj.minimize(dpar, ex);