C++ examples for Class:Member Function
Defining a Member Function in the Class
class MyAccount { public: //from w ww.j av a 2 s. c om // define a member function deposit() double deposit(double amount) { balance += amount; return balance; } unsigned int accountNumber; double balance; }; #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; 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; }