function defintion in header file in C++
<p>I have C++ project which consists of multiple (in fact many) .cpp and .h files. While writing header files i have a file as follows</p>

<p>For eg MyHeaderFile.h</p>

<pre><code>#ifndef _MYHEARDERFILE_H
#define _MYHEARDERFILE_H

// Here i have function defintion.
void myFunc() {cout &lt;&lt; "my function" &lt;&lt; endl; }

#endif
</code></pre>

<p>Above file is included in multiple files. While compiling i have getting "multiple definition of "myfunc" error.
I am expecting the header is included only once as i have #ifndef check so i am expecting error should not be thrown.</p>

<p>For example in case of templates we have to define in header file, in this case how we can avoid the problem i am facing now?</p>

<p>Can any one please help me why i am seeing the error? is my understanding right?</p>

<p>Thanks!</p>
