+ 1
A member function or method is a function local to a class. It can only be accessed by the objects of the class, if it has a public access. It can access and alter private members of the class inside itself.
Eg :
class Ex
{
int a; // Member variable.
public:
void Print() { cout<<a<<endl; }
// Method to print private variable.
void Set(int x) { a = x; }
// Method to set value of variable.
};
int main()
{ Ex e; e.Set(5); e.Print(); }
Methods are accessed by objects using the dot '.' operator (member selection). For pointer to objects, they are accessed using '->'.
Eg :
Ex* e2 = new Ex; e2->Set(5); e2->Print();