code_junkie

What Does It Mean For a C++ Function To Be Inline?

Nov 11th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // my_thing.h
  2. inline int do_my_thing(int a, int b) { return a + b; }
  3.  
  4. // use_my_thing.cpp
  5. #include "my_thing.h"
  6. ...
  7. set_do_thing(&do_my_thing);
  8.  
  9. // use_my_thing_again.cpp
  10. ...
  11. set_other_do_thing(&do_my_thing);
  12.  
  13. use_my_thing_again.obj : error LNK2005: "int __cdecl do_my_thing(int,int)" (?do_my_thing@@YAHHH@Z) already defined in use_my_thing.obj
  14. <...>Scratch.exe : fatal error LNK1169: one or more multiply defined symbols found
  15.  
  16. int foo();
  17. inline int bar();
  18.  
  19. int foo(){ int r = bar(); return r; }
  20.  
  21.  
  22. inline int bar(){ return 5;};
  23.  
  24. #include "inlinetest.h"
  25. int main()
  26. {
  27. foo();
  28. //bar();
  29. }
Add Comment
Please, Sign In to add comment