Should modifying an inline member function cause recompiling the whole class?

84 Views Asked by At

Hello I know that if the compiler inlines a function, it replaces its body (statements) in each call to it.

I've read this from Stroustrup's programming principles and practice using c++ about defining a class member function within the class body:

All uses of the class will have to be recompiled whenever we make a change to the body of an inlined function. If the function body is out of the class declaration, recompilation of users is needed only when the class declaration is itself changed. Not recompiling when the body is changed can be a huge advantage in large programs.

  • So for example:

    struct Foo{
       void say_hello(std::string const& msg){ std::cout << "Hello " << msg << '\n'}; //implicitly inlined
       int getVal() const{ return som_val;} // implicitly inlined 
       inline void bar(); // maybe inline, defined outside
    };
    
    void Foo::bar(){}
    
    Foo the_foo;
    the_foo.say_hello("world");
    
  • Does he mean that if I change the body of say_hello will cause the whole class be recompiled?

  • If so then what is the difference between say_hello and bar? the latter is marked inline but defined outside of the class body.

Can someone explain to me what he means and the mechanism of inlining and not recompiling and when recompiling is needed with small examples? Thank you so much!

0

There are 0 best solutions below