Can you please suggest how I can avoid such a linker error without moving my function some where else?
So I have 3 header files: a.hpp, b.hpp, and c.hpp. a #include b, b #includes c, c include #a. All of the header files have header guard. There is a function in b.hpp, called addition which takes 2 integers and return the sum of them. When I call the addition() in my main, it doesn't compile and throws a linker error. I would think header guard on each file would avoid the error but it just doesn't.
It's from my school project. We were given a solution that already has codes in, and we need to extend it to complete some tasks. Some header files directly or indirectly include each other.
//salem c
Thank you for testing this. I run my codes on visual studio and it doesn't compile.
I don't have Visual Studio, so I don't know exactly why :-) but it's a good habit to put the function prototypes into the headers and the definitions into the 'source' files.
Maybe Visual Studio is set to consider it more an obligation than a habit (just an hypothesis).