linkage - inline functions link error C++ -


consider following code:

in header.h

#pragma once  class someclass { public:     void foo(); }; 

in header.cpp

#include "header.h"  inline void someclass::foo(){} 

in main.cpp

#include <iostream> #include "header.h" using namespace std;  int main() {     someclass obj;     obj.foo(); } 

here link error because foo function defined inline in header.cpp, if remove 'inline' keyword, compile , run proceed without errors.

please tell me why link error on 'inline' function?

the way wrote it, inline applies current file scope. when inline function in header, header included in cpp file, , function inlined used in file's scope, there no problem. in case, function available inline defined, , no other cpp file sees it, except regular member declaration in class, hence link error.

if want inline, add code , inline keyword in header.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -