2 BankAccount Class Copy Constructor Add a copy constructor

2. BankAccount Class Copy Constructor
Add a copy constructor to the BankAccount class. This constructor should accept a
BankAccount object as an argument. It should assign to the balance field the value in the
argument’s balance field. As a result, the new object will be a copy of the argument object.

Solution


Copy Constructor:

class BankAccount {
  
   private:
       double balance; // instance variable
  
   public:
       // copy constructor
       BankAccount(const BankAccount &other){
           balance = other.balance; // copying other\'s balance in current account
       }
}

2. BankAccount Class Copy Constructor Add a copy constructor to the BankAccount class. This constructor should accept a BankAccount object as an argument. It sh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site