member functions of a classa member function of


Member Functions of a Class

A member function of the class is similar as an ordinary function. Its declaration in a class template must explain its return value as well as the list of its arguments. You can declare or explain the function in the class specifier itself, in which case it is just like a normal function. But since the functions within the class specifier is considered inline by the compiler we should not explain large functions and functions with control structures, iterative statements etc should not be written inside the class specifier. Though, the definition of a member function differs from that of an ordinary function if written outside the class specifier. The header of a member function uses the scope operator (::) to state the class to which it belongs. The syntax is:

return_type  class_name :: function_name (parameter list)       

             {

                :

                }

 

e.g.

                void player :: getstats (void)

                 {

                                :

                 }

                void player :: showstats (void)

                 {

                                :

                                :

                 }

This notation shows that the functions getstats () and showstats() belong to the class player.

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: member functions of a classa member function of
Reference No:- TGS0309359

Expected delivery within 24 Hours