lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*()


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 8fd00bb 34/65: rework operator*()
Date: Wed, 16 Sep 2020 16:55:17 -0400 (EDT)

branch: valyuta/002
commit 8fd00bbc27eb317fd9370ba2f780ad8015007f17
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    rework operator*()
---
 currency.hpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index 9c5c2b3..66db12e 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -113,9 +113,9 @@ class currency
     // Far too permissive:
 //  currency& operator*=(double z) {m_ = static_cast<data_type>(100.0 * 
to_double() * z); return *this;}
     // wrong: doesn't affect '*this'
-    double operator*=(double z) {return to_double() * z;}
+//  double operator*=(double z) {return to_double() * z;}
 // Dangerous--can somehow take the place of operator*(double)
-//  currency const& operator*=(int z) {m_ *= z; return *this;}
+    currency const& operator*=(int z) {m_ *= z; return *this;}
 
     data_type m() const {return m_;} // restrict to friends?
 
@@ -191,7 +191,11 @@ inline currency operator+(currency lhs, double rhs) 
{return lhs += currency(rhs)
 inline currency operator-(currency lhs, double rhs) {return lhs -= 
currency(rhs);}
 //inline currency operator*(currency lhs, double rhs) {return lhs *= 
currency(rhs);}
 ////inline double operator*(currency lhs, double rhs) {return lhs *= 
currency(rhs);}
-inline double operator*(currency lhs, double rhs) {return lhs.operator*=(rhs);}
+// Don't actually want any member operator*() for double:
+inline double operator*(currency lhs, double rhs) {return lhs.d() *  rhs;}
+inline double operator*(double lhs, currency rhs) {return lhs *  rhs.d();}
+inline currency    operator*(currency lhs, int    rhs) {return lhs *= rhs;}
+inline currency    operator*(int    lhs, currency rhs) {return rhs *= lhs;}
 //inline currency operator*(currency lhs, int rhs) {return lhs *= rhs;}
 //inline currency operator*(int lhs, currency rhs) {return rhs *= lhs;}
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]