So I have a base class with the following header file:
#ifndef ODESolver_H
#define ODESolver_H
#endif
#include "DoublePendulum.h"
class ODESolver
{
public:
ODESolver(DoublePendulum &);
virtual void Predict(const double &)=0;
DoublePendulum DP;
};
Implementation:
#include "ODESolver.h"
#include <iomanip>
ODESolver::ODESolver(DoublePendulum &DPRef) :DP(DPRef)
{}
And a class that inherits from it:
#ifndef ODEEuler_H
#define ODEEuler_H
#endif
#include "ODESolver.h"
class ODEEuler : public ODESolver
{
public:
ODEEuler(DoublePendulum &);
void Predict(const double &);
};
Implementation:
#include "ODEEuler.h"
ODEEuler::ODEEuler (DoublePendulum &DPRef) :ODESolver(DPRef)
{}
void ODEEuler::Predict(const double &dt=0.005)
{
DP=DP+DP.Derivate()*dt;
cout << DP.getUp().getTheta() << endl;
}
The problem is that in the above implementation, DP=DP+DP.Derivate()*dt; won’t do anything. I have no clue how this is possible. I have checked if the .Derivate() member function works and it actually returns the correct values/object. On top of that, it doesn’t matter what I do there e.g. DP=DoublePendulum RandomObject(1,2,3,4) will still keep DP the same. Any ideas? I hope I provided enough information…
Also the implementation and declaration of DoublePendulum etc:
This assignment operator
creates a new value, but does not really assign anyting to the left-hand-side of the assignment. That’s why it doesn’t change!
The standard form of assignment looks like