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
}
}
