Quantity: Added -= and += operators.

This commit is contained in:
Eivind Kvedalen
2016-03-27 01:29:25 +01:00
committed by wmayer
parent 0e45008f9a
commit d6052a5a27
2 changed files with 23 additions and 0 deletions

View File

@@ -113,6 +113,17 @@ Quantity Quantity::operator +(const Quantity &p) const
throw Base::Exception("Quantity::operator +(): Unit mismatch in plus operation");
return Quantity(this->_Value + p._Value,this->_Unit);
}
Quantity& Quantity::operator +=(const Quantity &p)
{
if(this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator +=(): Unit mismatch in plus operation");
_Value += p._Value;
return *this;
}
Quantity Quantity::operator -(const Quantity &p) const
{
if(this->_Unit != p._Unit)
@@ -120,6 +131,16 @@ Quantity Quantity::operator -(const Quantity &p) const
return Quantity(this->_Value - p._Value,this->_Unit);
}
Quantity& Quantity::operator -=(const Quantity &p)
{
if(this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator -=(): Unit mismatch in minus operation");
_Value -= p._Value;
return *this;
}
Quantity Quantity::operator -(void) const
{
return Quantity(-(this->_Value),this->_Unit);