inline functions

I don't really understand inline functions.what inline does is that it replaces the called function with the code inside the function.so why doesn't this work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #include <iostream>
#include <string>
using namespace std;
void bob(int a,int b)
{
     a+b;

}
int main()
{
    int x;
x = inline bob(1,2);
cout<<x;

       //cout<<f;//bob(1,2);
}
inline goes on the function declaration, not where you use it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include <iostream>
#include <string>
using namespace std;
inline void bob(int a,int b)
{
     a+b;

}
int main()
{
    int x;
x =  bob(1,2);
cout<<x;

       //cout<<f;//bob(1,2);
}


Also, your function bob returns void. It doesn't return anything. So how are you expecting this to work:
x = bob(1,2);
given that the function bob doesn't return a value?
Last edited on
Topic archived. No new replies allowed.