what is the use of inline??

this code also works when i do not use inline keyword..so what is the use of this keyword??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream.h>
#include<conio.h>

class student
{
      char name[10];
      
      public:
             void output();
};

inline void student::output()
             {
                  printf("enter name");
                  scanf("%s",name);
                  printf("name is %s",name);
             }
int main()
{
    student a;
    a.output();
    getch();
     
}
The difference is that inline functions are not subject to the one-definition rule. Try to define the function again in a different translation unit. Without inline, you will get a linker error, with inline the linker will pick one of the definitions and succeed.
Topic archived. No new replies allowed.