Posts: 266
Threads: 239
Joined: Apr 2011
Kindly explain a little bit what is member function and non member function and also tell what are member operator and non member operator.
In case of member function of class:
Posts: 9,583
Threads: 8,089
Joined: Apr 2011
A non- member function always appear outside of class body. A member function can also appear outside of class body, but the member function must be qualified by the name of its class.
For example:
int student :: myfunction(int a, int b){//member function
------------
}
Int myfunction (int a, int b){ //Non member function
------------------
}
Another difference between member and non member functions is how that are called in the main program.
Consider the following segment of code:
Int main () {
int I;
student std;
I=myfunction (3, 2);// invoking the non-member function
I=std.myfunction (3, 2); // invoking the member function
}
A member operator is typically used when
• The operator modifies the value of the object to which it is applied, requiring it access to the object’s data members. Or,
• The operator requires access to the object’s internal state, represented by data members which are not otherwise accessible (through a public method). In all other instances a nonmember operator is to be preferred. This ensures that there’s that much less chance of the object’s data members getting inadvertently modified (which is only possible from a member method) and at the same time not increasing the size of the object.
The member function of a class takes more than one parameters, depends upon the nature of the function.
Return 0 means that the program ended successfully. When the return statement is used at the end of main, the value 0 indicates that the program has terminated successfully. Any other value is an error code that can be used by whatever program started your program.