I've got a functor that takes a lat3d object as a parameter, and I want to pass this functor to a root finding routine that adjusts ef. The functor looks like:
struct NormalizeNer {
NormalizeNer(lat3d &lat) : lat(lat) {}
double operator()(const double ef) {
lat.setEf(ef);
// some other irrelevant code
}
public:
lat3d lat;
};
The functor is instantiated and passed to the root finding routine findRoot as:
lat3d lattice();
NormalizeNer normalize(lattice);
double efroot = findRoot(normalize, eflo, efhi, eftolerance);
This works, except that using my class member function lat.setEf(ef) in line 4 only updates lat.Ef in a copy of the lat3d object. I want to be able to pass the lat3d object by reference so I can later get out the last updated value of Ef:
double lastEf = lattice.Ef
Any ideas how to pass by reference here? Apparently using lat3d &lat in line 2 doesn't work. Thanks!
The member variable lat
should be a reference as well:
lat3d ⪫
In your current code, the NormalizeNer
constructor accepts a reference but then makes a copy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With