Hi while compiling I get multiple def. errors like this
1 2 3
SubVecProcessor.o: In function `chrtopch(char)':
SubVecProcessor.cpp:(.text+0x0): multiple definition of `chrtopch(char)'
subv.o:subv.cpp:(.text+0x0): first defined here
Fyi I built a program with a similar structure. And it complies fine without any errors.
I have to say, I'm a looser at Makefiles. :D
Thanks in advance =)
The problem is that chrtopch will be defined each time for each .cpp file that includes functionlib.h. This is not allowed for regular functions. The solution is to mark it as inline or define it inside a .cpp file and just declare it in the header file.
To me, it looks like you're including it once in SubVecProcessor.cpp and once in subv.cpp. The linker is therefore finding two definitions for each of those functions.
As Peter87 says, you should put the function definitions into a separate .cpp file, rather than including them in multiple .cpp files (via a header). You'll still need the function declarations in the heaser, but the definitions should go into a .cpp.
No nothing has changed. I only deleted a few comment lines. And I'm not referring to the warnings. They are self-explanatory.
I have to use char because I'm handeling a dirent structure on a UNIX system to get a file tree.
The linking error is exactly my point.
I split the .h in to .cpp and .h and now get this.
The function convertVec does exist in scope as you can see on top.
The implementation of function templates has to be available when they are used so you have to define convertVec in the header. Templates are special so you will not get a multiple definition errors by doing so.
To get rid of the warning you should at least put a const.
For templates, you need to keep the function definitions in the header file. This is because the class is created by the compiler at compile-time from the template and its parameters, so the entirety of the template definition needs to be included in the header.
The other functions need to have their definitions in the .cpp file.