I have a variable ntot_sols who's final value isn't known when my object is constructed.
Consequentially I want to store a reference to the variable instead of the value since it's subject to change.
I think the following code will do it.
struct ItemWeighter {
int nsols;
int ntot_sols;
ItemWeighter(int _nsols, int& _ntot_sols) {
nsols = nsols;
ntot_sols = _ntot_sols;
}
float weight() {
return nsols / float(ntot_sols);
}
};
But I'm surprised that ntot_sols is type int and not int &. How does the variable know that it's a reference?