To perform type-specific operations at construction time, add a separate ImplementConstructor method to the implementation class. Call it from the class template's constructor, after the implementation class is constructed.
To perform type-specific operations at destruction time, add an ImplementDestructor method to the implementation called from the class template's destructor.
Here is the wrong way to implement the TOwningStackOf copy constructor:
template <class AType> TOwningStackOf::TOwningStackOf(const TOwningStackOf<AType>& other) : TOwningStackOfImplementation(other) { } TOwningStackOfImplementation::TOwningStackOfImplementation( const TOwningStackOfImplementation& other) : fCount(other.fCount) { for ( unsigned int i = 0; i < fCount; i++ ) {
TOwningStackOf::TOwningStackOf(const TOwningStackOf<AType>& other) { ImplementConstructor(other); } void TOwningStackOfImplementation::ImplementConstructor( const TOwningStackOfImplementation& other) { fCount = other.fCount; for ( unsigned int i = 0; i < fCount; i++ ) { fStack[i] = TypeSpecificCopy(other.fStack[i]); } }