Re: [C++]Templates

From: Brian Gray (mandy@NETCOM.COM)
Date: 08/28/97


On Thu, 28 Aug 1997, Bode, Wyatt wrote:

>     Anyway, I was trying to get a handle on templates so I could try and
> port Circle to C++.  Does anyone have some helpful hints on how to
> tackle it?  I know that several others on the list are doing the same,
> so why not share the wealth?  I was going to use the LinkedList template
> to keep track of all the various data classes but not have to mess
> around with multiple inheritance.

First bit of advice:  don't reinvent the wheel.  The Standard C++ Library
is our friend (it is allowed to access our private data ;) ), and it has
two template classes called <dynarray> and <ptrdynarray>.  Use dynarray
for lists of values and ptrdynarray for lists of pointers.  A detailed
description of how and why to use these and other libraries (such as
bits and bitstring) can be found in "The Draft Standard C++ Library" by P.J.
Plauger.

> Has anyone sat down with structs.h
> and made a roadmap of all the data structs?  I've looked through it
> myself, but some of the fields are still unclear as to their purpose.

Never actually done it, but it doesn't look too difficult.  You need an
abstract base for all things that appear inside of the world, like
objects, mobiles, and players.  Depending on whether or not you want to
have sentient objects (switchable, do socials...could be fun), either
derive all three classes straight from the base, or put player and mob
through an intermediary Character class.  The descriptor should be its
own class, and could probably attach to any Thing.  It should handle all
its own command-line interpreting and be responsible for sanity checking
of the commands sent to the Thing attached to it.  Obviously, this is the
perfect place to use RTTI.

If you want to get fancy, you can derive both classes and races from
Player, which would then have to be made abstract.  Then multiply inherit
a class and a race into your final Adventurer or whatever you want to
call it.

There are tons of ways to organize a project this large.  The above is
only one example, but it's how I would do it.

 -- Brian


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST