Regarding Inline Storage

Hi all,

lets take a sample code

class A
{
int c;
public:
inline int func(int a,int b)
{
c=a+b;
}

};

int main()
{
A a;
int (*p)(int,int); //function pointer
p=&(a.func);
}
//in general if compiler sees the inline type it copies the declaration,arguement,return types and method body into symbol table.
but in the main we need to store the address of func then what does the compiler do?? does it remove the code from symbol table and give memory to that inlne function as it does for mon-inline functions and place that code in that address??

Last edited on
but in the main we need to store the address of func then what does the compiler do??


Well, for starters, it won't compile because...

p=&(a.func); <-- this is not legal in C++


But assuming it was legal... the inline keyword is just a suggestion. In this case, the function will be callable and the function pointer would point to the body of that function just as if it were not inline.

Of course.. just because the function is not inlined in this case does not mean it can't be inlined when it is called directly.
Also functions defined inside class declaration are implicitely inline by default:
http://stackoverflow.com/a/9734378/3410396
https://isocpp.org/wiki/faq/inline-functions#inline-member-fns-more
Topic archived. No new replies allowed.