I'm attempting to overload a += operator with the following line:
a = b += c += 100.01; but my second += in that code shows an error as it matches no implementation i guess?
Heres my full relevant code:
main.cpp:
#include <iostream> #include "Account.h" using namespace sict; void displayABC(const Account& a, const Account& b, const Account& c) { std::cout << "A: " << a << std::endl << "B: " << b << std::endl << "C: " << c << std::endl << "--------" << std::endl; } int main() { Account a("No Name"); Account b("Saving", 10000.99); Account c("Checking", 100.99); displayABC(a, b, c); a = b + c; displayABC(a, b, c); a = "Joint"; displayABC(a, b, c); a = b += c; displayABC(a, b, c); a = b += c += 100.01; displayABC(a, b, c); return 0; } Account.h (Relevant definitions)
class Account{ public: friend Account operator+(const Account &p1, const Account &p2); Account& operator+=(Account& s1); Account & operator=(const char name[]); friend double & operator+=(double & Q, Account & A); Account & operator=(Account D); }; Account operator+(const Account &p1, const Account &p2); double operator+=(double& d, const Account& a); }; Account.cpp (relevant implementations)
Account& Account::operator+=(Account &s1) { double b = this->balance_ + s1.balance_; this->balance_ = b; return *this; } Account & Account::operator=(Account D) { strcpy(name_, D.name_ ); this->balance_ = D.balance_; return *this; } Account & Account::operator=(const char name[]) { strcpy_s(name_, name); return *this; } double & operator+=(double & Q, Account & A) { Q = Q + A.balance_; return Q; } So my question is, how do i change my implementations correctly to run this function: a = b += c += 100.01;
Thank you.