473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

templates and abstract base classes

Is it possible to realise an abstract base class with a template? 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 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?
Jun 27 '08 #1
6 2007
Dan Smithers wrote:
Is it possible to realise an abstract base class with a template?
"Realise"? Do you mean instantiate or implement?
The
reason that I'm considering this is that I would like to present a fixed
interface that I realise
Ah... You probably mean "implement".
using a completely independent implementation
module and avoid including the template code in the client code.
Why is it a template?
>
I want something like this:

interface.

ILog
{
public:
virtual void method() = 0;
virtual ~ILog;
virtual ~ILog();
static ILog& create();
protected:
ILog();
};

realisation:

template <typename T>
class CLog:ILog
{
public:
virtual void method();
virtual ~CLog;
virtual ~CLog();
static CLog& create();
protected:
CLog();
}
;
>
Am I actually trying to make this more complicated than it needs to be?
"More complicated" - in what sense? I don't see the use of 'T' anywhere
in your 'CLog'. What would be the point? How would you use your 'CLog'
template?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #2
On Jun 19, 10:20*am, Dan Smithers <dsmith...@talktalk.netwrote:
Is it possible to realise an abstract base class with a template?
Of course. Didn't you try it?
Am I actually trying to make this more complicated than it needs to be?
Most certainly.

Jun 27 '08 #3
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
Jun 27 '08 #4
joseph cook wrote:
On Jun 19, 10:20 am, Dan Smithers <dsmith...@talktalk.netwrote:
>Is it possible to realise an abstract base class with a template?

Of course. Didn't you try it?
yes, but it didn't work. I thought asking a quick question first would
be better than spending a lot of time not getting it to work and then
asking the question.
>
>Am I actually trying to make this more complicated than it needs to be?

Most certainly.
Jun 27 '08 #5
Thanks for your reply

Road.Tang wrote:
>
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.
That's what I'm hoping to do. I want to write a library that conforms to
the interface that the client can use without knowing what is being used
to implement it. The template code would be included inside the library
and hidden from the client.

thanks

dan
Jun 27 '08 #6
Dan Smithers wrote:
joseph cook wrote:
>On Jun 19, 10:20 am, Dan Smithers <dsmith...@talktalk.netwrote:
>>Is it possible to realise an abstract base class with a template?
Of course. Didn't you try it?

yes, but it didn't work. I thought asking a quick question first would
be better than spending a lot of time not getting it to work and then
asking the question.
FAQ 5.8.
>
>>Am I actually trying to make this more complicated than it needs to be?
Most certainly.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
9
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must...
18
by: Bradley | last post by:
I'm trying to determine if there's a general rule for when an Interface should used vs. an Abstract Class. Is there any design advantage to using one or the other? Brad
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
23
by: Ben Voigt | last post by:
I have a POD type with a private destructor. There are a whole hierarchy of derived POD types, all meant to be freed using a public member function Destroy in the base class. I get warning C4624....
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
2
by: cmonthenet | last post by:
Hello, I searched for an answer to my question and found similar posts, but none that quite addressed the issue I am trying to resolve. Essentially, it seems like I need something like a virtual...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.