I have a perfectly working code:
template <typename ...Ts>
class ThreadImplementation {
...
void launch(){...}
~ThreadImplementation(){...}
};
...
ThreadImplementation<Ts...> *t = new ThreadImplementation<Ts...>(debugName,func,args...);
...
// std::vector< std::unique_ptr< ThreadImplementation<> > > thread_107_allThreads;
thread_107_allThreads.emplace_back(t);
...
where thread_107_allThreads as of now stores only the ones with no template parameters, hence ThreadImplementation<> in the declaration
now if I add above all
class AnyThreadImplementation {
public:
virtual void launch() = 0;
virtual ~AnyThreadImplementation() = 0;
};
and make ONLY the following 3 changes (no casting, no change in use, nor in test):
class ThreadImplementation : public AnyThreadImplementation {
virtual void launch(){...}
virtual ~ThreadImplementation(){...}
(although the last 2 changes does not affect the result ie: I get the same error if I miss the virtual's in front of the actual implementations in the subclass)
and I get:
/tmp/test-fuPonc.o: In function `_ZN20ThreadImplementationIJEEC2EPKcPFvvE':
test.cpp:(.text._ZN20ThreadImplementationIJEEC2EPKcPFvvE[_ZN20ThreadImplementationIJEEC2EPKcPFvvE]+0xbb): undefined reference to `AnyThreadImplementation::~AnyThreadImplementation()'
/tmp/test-fuPonc.o: In function `_ZN20ThreadImplementationIJEED2Ev':
test.cpp:(.text._ZN20ThreadImplementationIJEED2Ev[_ZN20ThreadImplementationIJEED2Ev]+0x233): undefined reference to `AnyThreadImplementation::~AnyThreadImplementation()'
test.cpp:(.text._ZN20ThreadImplementationIJEED2Ev[_ZN20ThreadImplementationIJEED2Ev]+0x267): undefined reference to `AnyThreadImplementation::~AnyThreadImplementation()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why ?