Friends Classes can declare other classes, other classes' member functions etc as friends and can access protected and private data members and methods. Example, given two classes A and B , you can say B is a friend of A as follows: class A { friend class B ; } Now all the methods of B can access the private and protected data members and methods of A . Dynamic memory allocation in objects If the amount of memory needed is unknown ahead of time, objects can dynamically allocate memory. Assume the CheckingAccount class from the previous article is updated as follows to include account number: checkingaccount.h : # ifndef CHECKING_H # define CHECKING_H # include <string> using std :: string ; class CheckingAccount { public : CheckingAccount ( std :: string accountNumber , double balance ) ; ~ Ch...
Comments
Post a Comment