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
For eg MyHeaderFile.h
#ifndef _MYHEARDERFILE_H #define _MYHEARDERFILE_H // Here i have function defintion. void myFunc() {cout << "my function" << endl; } #endif 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.
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?
Can any one please help me why i am seeing the error? is my understanding right?
Thanks!
MYHEADERFILE_H_, because names with leading underscores are reserved by the implementation.