D
Daniel
It's been about 11 years since I've programmed in this language.
Anyway, using Visual Studio 2005 ...
I'm using a third party library that requires me to implement the
virtual operator
class CostFunctor
{
double operator()(const std::vector<double>& v) const {
...
}
double* x;
int dimx;
MyData* data;
}
Within this operator, I need to change the implementation to delegate
to a C function,
void costFunction(double *v, int dimv, double *x, int dimx, void
*data);
costFunction doesn't change v, does change x, and also changes data
(after casting back to MyData*.).
v I pass as const_cast<double*>(&v[0]).
I tried declaring x and data with mutable. That worked for data. But
when I tried declaring x as
mutable double* x;
it compiled, but resulted in a runtime "write to protected memory"
error inside costFunction. I then tried
double* mutable x;
which worked, but why that and not the other?
Any comments on the safest way of implementing this interface would be
appreciated (it's not possible to modify the interface of CostFunctor
or the signature of costFunction.)
Thanks,
Daniel
Anyway, using Visual Studio 2005 ...
I'm using a third party library that requires me to implement the
virtual operator
class CostFunctor
{
double operator()(const std::vector<double>& v) const {
...
}
double* x;
int dimx;
MyData* data;
}
Within this operator, I need to change the implementation to delegate
to a C function,
void costFunction(double *v, int dimv, double *x, int dimx, void
*data);
costFunction doesn't change v, does change x, and also changes data
(after casting back to MyData*.).
v I pass as const_cast<double*>(&v[0]).
I tried declaring x and data with mutable. That worked for data. But
when I tried declaring x as
mutable double* x;
it compiled, but resulted in a runtime "write to protected memory"
error inside costFunction. I then tried
double* mutable x;
which worked, but why that and not the other?
Any comments on the safest way of implementing this interface would be
appreciated (it's not possible to modify the interface of CostFunctor
or the signature of costFunction.)
Thanks,
Daniel