I get this error when i try to compile my code: non-static reference member ‘Timestep& Timestep::previousTimestep’, can’t use default assignment operator
I create one Problem which creates a Timestep a reference to the this Timestepshould be stored in the vector solution. Besides i want to store a reference to a previous Timestep - and for the first Timestep that would be a reference to itself...
I read that i need to define an own operator if i have const members in a class what i try to set equal. However, removed all const elements form the code and it still don't work. Any suggestions? Thanks a lot.
class Problem { public: void initialTimestep(arma::vec ic); private: std::vector<Timestep> solution; }; void Problem::initialTimestep(vec ic){ Timestep myFirstTimestep(starttime, ic, nodes); solution.push_back(myFirstTimestep); } class Timestep { public: Timestep(double starttime, arma::vec initialCondition, arma::vec nodelist); private: Timestep& previousTimestep; //const }; Timestep::Timestep(double starttime, vec initialCondition, vec nodelist) : previousTimestep(*this) { //do stuff } int main() { int k = 3; //subdomains vec v = linspace(0., 1., k+1); //node spacing vec ic= ones<vec>(k+1); //initialconditions Problem myProblem(v, ic, 0., 1., 0.1); return 0; }