You need to redeclare T
as a template type name in the implementation file:
#include "MyCairoControl.h"
template<class T>
MyCairoControl<T>::MyCairoControl(T *plug, IRECT container) : IControl(plug, container), pPlug(plug) {
// t->somethings();
}
template<class T>
MyCairoControl<T>::~MyCairoControl() {
}
The original problem is two fold. Firstly, T
as a symbol needs to be known as the template parameter. The template<class T>
lines added to the implementation signatures does this - it defines what T
means. Secondly, you need to realise that the type to which the constructor and destructor - and, indeed, any member - belongs is no longer MyCairoControl
but MyCairoControl<T>
. The left hand side of the scope-resolution operator now needs to be that.
There is a further concern to be noted. As it stands, the implementations of the class members are in a separate file from the header and this could present a problem. Consumers of the class will include the header and not the source file and so they will not be able to use the template - for example, if they try to use MyCairoControl<Foo>
they will get unresolved symbol errors. This can be fixed if you know the types that will be used for T
. Concretely, if you declare specialisations in MyCairoControl.cpp
as follows:
template <>
class MyCairoControl<Foo>;
template <>
class MyCairoControl<Bar>;
Anyone will be able to use MyCairoControl<Foo>
and MyCairoControl<Bar>
but trying to use MyCairoControl<OtherType>
will still give unresolved external symbol errors until you add a forward declaration for it, too.