cross-platform c++ classes?

Rob Wehrli plug-devel@lists.PLUG.phoenix.az.us
Mon May 21 09:51:00 2001


Lucas Vogel wrote:
> 
> I am looking to create a development library based on a cross-platform API.

It sounds more as if you want to create a cross-platform API that is
your library.

> The way I would like to develop my library would be to create a "core set"
> of c++ classes, with platform-specific implementations(i.e., a COM subset

Why would the C++ "core set" have platform specific implementations? 
The core set should use an appropriate interface definition that
abstracts the implementation details specific to a platform such that it
appropriate hides it from the core API, which is really the only
practical way to make it "cross-platform."

> for windows) based on these core classes. The API that I am developing off
> of is implemented on Windows, (Red Hat) Linux and SGI(IRIX I think).

COM is a binary standard, not a Windows "platform" specific API.  There
is no real reason why you couldn't write a COM implementation for
Linux.  Microsoft wrote one for Solaris and, obviously, its Win32
platforms.  In fact, in many ways, COM is the design model you probably
want to follow for your own API.

I'm assuming that you're thinking of some GUI that is the "platform
specific" portion of your code.  There are a number of existing
cross-platform GUI libraries that you could use to easily mitigate that
risk and not assume such responsibility in your own code.  V is an
example that comes to mind.  QT, too.  Probably more than a dozen others
are out there, many of them Open Source.

> 
> My question to the council is, how do I create this core set of classes so
> that they are also cross-platform compatible? Any and all
> recommendations/suggestions would be greatly appreciated.

Take a closer look at your use of interfaces and interface inheritance,
write a few sample classes to get an idea of how you can exploit them
and start using them in your development objective.  Consider the means
by which Java uses to accomplish its goals and try to gain an
understanding of how that could be accomplished using C++.  Remember the
lessons learned from what COM is from the COM component implementor's
and users' perspectives; you create/gain a "handle" to an interface,
create/query interfaces available from it and implement/use the desired
interface(s) to do your work.  These features are made available to you
within the implementation of the cpp classes you create through the
vtable.  Brush up on your understanding of using typelib so that your
classes, where appropriate, are "self-describing" and locate a copy of
the ARM for your deskside reference needs.  Lastly, don't let anyone
tell you that C++ is easy.  It is an extremely feature-rich language
that doesn't prevent you from chopping off your arm with obtusely poor
design and implementation choices.  I've got a number of good book
recommendations if you're really interested.

> 
> Thanks guys!
> 
> ===========================
> Lucas Vogel
> lvogel@exponent.com
> 623-587-6739    work
> 623-587-4191    fax
> ===========================

Take Care.

Rob!