Defining Member Function in C++
Defining Member Function :- Member function can be defined inside as well as outside the class definition. Now the member functions declared inside the class can be defined outside the class definition in the following way :
return_type class_name :: funs_name(arguments)
{
function body
}
So ,following this concept the member function defined as follows -
void point :: getpoint (int a, int b);
{
x = a;
y = b;
}
void point :: showpoint(void);
{
cout<<”x_coordinate :”<<x<<\n “;
cout<<”y_coordinate :”<<y<<\n “;
}
We can also define the above member functions inside the class definition
class point
{
int x;
int y;
public:
void getpoint (int a, int b);
{
x = a;
y = b;
}
void showpoint (void);
{
cout<<”x_coordinate :”<<x<<\n “;
cout<<”y_coordinate :”<<y<<\n “;
}
};
When a function is defined inside a class, it is treated as an inline function.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment