Private Member Functions

Although it is normal practice to place all the data items in a private section and all the function in public, some situations may require certain function to be hidden from the outside calls. Tasks such a deleting an account in a customer file, or providing increment to an employee are event of serious consequences and therefore the function handling such task should have restricted access. We can place these function in the private section.

A private member function can only be called by another function that is a member of its class. Even an object cannot invoke a private function using the dot operator. Consider a class as defined below:
class sample
{
int m;
void read(void);
public:
void update(void);
void write(void);
};

1 comment: