C++ Class Member Function change the member field value
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; class MyAccount/*from w w w. j ava 2s. co m*/ { public: double deposit(double amount) { balance += amount; return balance; } unsigned int accountNumber; double balance; }; int main(int nNumberofArgs, char* pszArgs[]) { MyAccount s; s.accountNumber = 123456; s.balance = 0.0; cout << "Depositing 10 to account " << s.accountNumber << endl; s.deposit(10); cout << "Balance is " << s.balance << endl; return 0; }