On Jun 19, 10:20 pm, Dan Smithers <dsmith...@talktalk.netwrote:
Is it possible to realise an abstract base class with a template?
yes, after template class is instanced, it's the same as the common
class.
The reason that I'm considering this is that I would like to present a fixed
interface that I realise using a completely independent implementation
module and avoid including the template code in the client code.
I'm afraid you can't avoid to #include template code.
since you must instance the template class CLog<T, at the instance
place, it must see the template definition. (the template export is
still not supported well in mainstream compilers).
but yes, use ILog, the client can be constructed using ILog interface,
i.e.
the client C++ programmer can work with little template knowledge,.
>
I want something like this:
interface.
ILog
{
public:
virtual void method() = 0;
virtual ~ILog;
static ILog& create();
protected:
ILog();
};
realisation:
template <typename T>
class CLog:ILog
{
public:
virtual void method();
virtual ~CLog;
static CLog& create();
protected:
CLog();
}
Am I actually trying to make this more complicated than it needs to be?
It depends what you need.
ILog can transfer template-form code into interface-form.
As mentioned, if client programmer doesn't like or know the template,
ILog (interface adaptor) is important.
-roadt