Hello everyone. This is my first post on this forum.
I have a huge problem with inheritance a partially specialized class (one method depends on type). My code looks ok, but something not working. Please help. This is very rare situation and i cannot find answer.
My template code (helpers/helperdataarray.h):
./release/colladafile.o:colladafile.cpp:(.text+0x2c): multiple definition of `daehelpers::HelperDataArray<float>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x2b0): first defined here
./release/colladafile.o:colladafile.cpp:(.text+0x618): multiple definition of `daehelpers::HelperDataArray<QString>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x458): first defined here
./release/colladafile.o:colladafile.cpp:(.text+0x7c0): multiple definition of `daehelpers::HelperDataArray<int>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0xfc): first defined here
./release/colladafile.o:colladafile.cpp:(.text+0x974): multiple definition of `daehelpers::HelperDataArray<bool>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x600): first defined here
./release/daegeometry.o:daegeometry.cpp:(.text+0x7c0): multiple definition of `daehelpers::HelperDataArray<QString>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x458): first defined here
./release/daegeometry.o:daegeometry.cpp:(.text+0x968): multiple definition of `daehelpers::HelperDataArray<int>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0xfc): first defined here
./release/daegeometry.o:daegeometry.cpp:(.text+0xb1c): multiple definition of `daehelpers::HelperDataArray<float>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x2b0): first defined here
./release/daegeometry.o:daegeometry.cpp:(.text+0xcc4): multiple definition of `daehelpers::HelperDataArray<bool>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x600): first defined here
./release/daefile.o:daefile.cpp:(.text+0x154): multiple definition of `daehelpers::HelperDataArray<bool>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x600): first defined here
./release/daefile.o:daefile.cpp:(.text+0x480): multiple definition of `daehelpers::HelperDataArray<QString>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0x458): first defined here
./release/daefile.o:daefile.cpp:(.text+0x628): multiple definition of `daehelpers::HelperDataArray<int>::ParseDataArray(QStringList const&)'
./release/helpersource_core.o:helpersource_core.cpp:(.text+0xfc): first defined here
...
Sorry for long listings but maybe problem lies elsewhere and additional code can be usefull to understand.
The reason this comes up, is that linker thinks, that the same functions have been implemented multiple times. But you implemented the functions that created the errors only once in the header file. Each header file is compiled every time it is included. Therefore the specialized functions are compiled multiple times and the linker complains.
Therefore, the solution to your problem is: Put the implementations of the template specializations into the cpp files. You can declare a specialization if you want to so for clarity. But you don't need to do so.
Your answer is very clear for me, thank you for quick reply. I was almost sure that I did so earlier, but maybe I've put whole implementation of template to *.cpp file (what is wrong what I've learned). For two years without a C++ is a lot to forget. Thanks alot.