[ADMB Users] How to use Autodif as a regular external C++ library?
dave fournier
davef at otter-rsch.com
Sun Nov 4 16:02:27 PST 2012
I was curious to see if you needed to change struct to class.
It appears not. But you do need to use new and delete
as this simple example shows.
#include <fvar.hpp>
struct mys
{
dvariable x;
};
main()
{
gradient_structure gs(1000000);
// this will work
mys u;
u.x=5;
cout << u.x << endl;
// this will work
mys * pu2 = new mys;
pu2->x=7;
cout << pu2->x << endl;
delete pu2;
pu2=0;
// this will crash
mys * pu=(mys*) malloc(sizeof(mys));
pu->x=6;
cout << pu->x << endl;
}
More information about the Users
mailing list