inline

what is the difference between the following codes? both are giving same output though...

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

class A
{
      public:
             void func ();
             
};
     
void A::func()
{
printf("sz");
}      
      
int main()
{
    A obj;
    obj.func();
    getch();
}


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

class A
{
      public:
             void func ();
             
};
     
inline void A::func()
{
printf("sz");
}      
      
int main()
{
    A obj;
    obj.func();
    getch();
}


and what is the use of inline keyword when we can achieve results without it?
Inlining is an optimization technique. Look it up in Google and then come back if you have doubts about what you read about it. Look up "c++ inline". The same works for other C++ keywords you may not understand.
function specifier inline is a recommendation to the compiler to inline the body of the function at the point where it is called.
In your example the compiler can inline the function without your recommendation. So the both examples can be totally equivalent.:)
okay ..i got it.thnx
Topic archived. No new replies allowed.