Consider the following code where the Writer_I acts as an interface. Other classes which fulfil the contract of writing element types in correct form can derive
Templates can have non-template base , so you may actually follow this scheme if its beneficial (can also save compile time by reducing need in declarations and complete types):
// Public interface header
class Writer {
// virtual interfaces, common public interface;
};
That would be base class for all Writer classes. The header would be minimalistic and doesn't include template code
// Private interface header (or unit if it is used in only one unit)
// As it contains actual implementation, it may require more headers
// or modules included than public header.
template < class Type > class WriterTypeTraits;
template < class Type >
class WriterInterface : class Writer, class WriterTypeTraits {
// internal implementation of virtuals, some may use CRTP
// construction, initialization and deletion depending on Type
// private members that shouldn't be seen
};
Code above would be used to create concrete classes and only where it's required to have types complete.
// The real writer
template <>
class WriterTypeTraits {
// definitions for RealWriter
};
class RealWriter : WriterInterface {
// implementation details, initialization for WriterInterface
// members specific to RealWriter
};
And we can have some kind of factory or creator functions (make_real_writer?) that creates of instances classes like RealWriter. WriterInterface here acts as mixin and of course there might be more than one of them, but in that case inheritance may require virtual inheritance to avoid secondary Writer subobjects.