b.WithDraw(1002,8000); b.WithDraw(1003,2000); b.WithDraw(1002,2000); }
运行结果:
1001 After deposit,the balance is: 1000 1001 After witndraw,the balance is : 500 1001 After deposit,the balance is: 2500 1001 After witndraw,the balance is: 1500 1002 After deposit,the balance is: 5000 1002 After witndraw,the balance is : 3000 The amount to witndraw is bebyond the balance. Illegal account_number!
1002 After witndraw,the balance is :1000
可见,类CbankAccount中的所有成员数据都被封装起来,外部对象不能直接访问它们。但可以通过公有成员函数MakeDeposit()、WithDraw()对它们进行间接的访问。
11