I am not familiar with templates, but I wonder, if it is possible to use them for setter and getter methods. For example in this situation:
double exmlClass::getA(void) const
{
return a_;
}
void exmlClass::setA(const double& a)
{
a_ = a;
}
double exmlClass::getB(void) const
{
return b_;
}
As you can see, methods are almost the same, except they refer to another private variables (a_, b_, c_). Is there a more elegant way to write those functions or it is common practice to do like above in such situations? And if its common to use templates, I would appreciate example how you would use them in code above.
Another question I would ask is how should getters and setters be properly declared. Is it good coding style?
double getA(void) const;
void setA(const double& a);
double getB(void) const;
void setB(const double& b);
double getC(void) const;
void setC(const double& c);
I mean should getters be always const and setters take as argument reference to an object, rather than copy it, which would be probably a little bit slower?