|
-
May 27th, 2002, 02:31 AM
#1
Need an architecture
I Have 2 classes "Writerthread" and "readerThread".
I have 2 other classes "WinThread" & "LinuxThread" which are base classes for the Writerthread" and "readerThread".
I want to derive these classes say,
class WriterThread ublic WinThread or
class WriterThread ublic LinuxThread
The problem is I want to do it dynamically.The writerthread should derive from 1 of these classes,depending on the operating system(ie:wheather it is linux or windows).In the main(), Iam using a
#ifdef _LINUX_
#endif
#ifdef _WIN_VER
#endif
I need an architecture so that I can derive from 1 of these classes dynamically.
I dont want to use #ifdef inside the classes
Thanks
-
May 27th, 2002, 05:52 PM
#2

Linux and Windows are two different operating systems ... I don't think you can do this check in run-time--don't you need to compile your program for these two OS?
Maybe I just don't get it
-
May 27th, 2002, 10:03 PM
#3
You can dynamically change a class's base class by using a template class and deriving from the template parameter. It would look something like this, although I didn't try to compile it.
template<class T>
class WriterThread : public T
{
};
then in main:
#ifdef _LINUX_
writer = new WriterThread<LinuxThread>();
#else
writer = new WriterThread<WinThread>();
#endif
Jeff
-
May 28th, 2002, 03:57 AM
#4
Re: Need an architecture
Why not something like
#ifdef _LINUX_
class WriterThread : public LinuxThread
#endif
#ifdef _WIN_VER
class WriterThread : public WinThread
#endif
If everything is well defined after that, you may be able not to use these defines in the rest of your class.
Elrond
A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
-- George Steiner
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|