Inline Member Function in C++ with example



The inline member function is basically used to insert the definition of the function at the calling portion.
The inline member function has some restrictions. For example in big programming construct is like looping etc. is not supported.

inline void student ::get()
{
cout<<”Enter the Student Info = ”;
cin>>id>>name;
}

Advantages of Inline Member Function
·        It increases execution speed.
·        The size of the object code is significantly reduced.
·        Well suited whenever a function is small.  

Example:
#include<iostream.h>
#include<conio.h>
class student
{
int id;
char name[20];
public:
void get();            //here get() is inline member function as it is define in student class
                              {
               cout<<”Enter the Student Info = ”;
cin>>id>>name;
}
               void put();            //here put() is inline member function as it is define in student class
                              {
                              cout<<”Student Info = ”;
                              cout<<id<<name;
}
};
void main()
{
clrscr();
student st;
               st.get();
               st.put();
               getch();
}

No comments:

Post a Comment