I just would like some input/critics/heads up on my class definition and implementation I did for my project.
Looks good. There are a couple of small issues, but other than that looks good. About the small issues now...
Your m_vector doesn't have to be a vector pointer. A vector object would be fine. This would greatly simplify
some things. E.g. your assignment operator (which, by the way, should return a reference) would look like this:
PNVector & PNVector::operator=(const PNVector &other) {
if (this!= &other)
this->m_vector = other.m_vector;
return *this;
} The rest of your operators could use some const qualifiers.
E.g. PNVector operator+(const PNVector &rhs) <strong>const</strong>;
Don't forget that at() performs bounds checking, which is unnecessary
in many cases in your code. You could just use operator[] instead.
If you intend to also provide +=, *=, ... etc operators (which is a good idea), you
should implement +, *, ... etc in terms of +=, *=, ... and not the other way around.
I.e. it should look like this:
PNVector & PNVector::operator += (double val)
{
// ...
return *this;
}
PNVector PNVector::operator + (double val)
{
PNVector ret(*this);
ret += val;
return ret;
} Is the only solution to make this work to overload the binary * and / respectively?
Yes. You have to also write global operator overloads (note that both global
and member operators are binary operators, as they accept two arguments).
Finally, note that if this is only a helper class for your runge kutta project, you can always use std::valarray instead.