Well, if you do change the type from struct to class, you may
need to change references to any local definitions within other
functions to reflect that. As far as access privlidges, I would say
to leave most of the char_data public, as these values must be
changed via pointers and that you will be the only one (most likely)
accessing it. Using public functions to change/return private data
types on the char_data may be a bit redudnant in this case.
But, I havn't looked at circle source in quite some time, so I may
be quite wrong =)
Franco Gasperino
Cutting Edge Communications
509-444-INET
http://www.cet.com/
awe@cet.com
----------
> From: Brian Gray <mandy@NETCOM.COM>
> To: CIRCLE@post.queensu.ca
> Subject: [CODE] Operator overloading (C++)
> Date: Monday, August 18, 1997 12:30 PM
>
> Howdy all. I just resubscribed about 5 minutes ago after about a 2-year
> break. Did I miss anything?
>
> Well to jump right in, anyone out there any good with C++? I've
> converted a Circle-based game to C++ just as far as getting it to compile
> with g++. In other words, I've not yet redesigned the architecture to
> use proper classes and object-orientedness.
>
> Anyhoo, I thought it would be swell to overload the operator<< for
> char_data in effect to replace send_to_char. I did this in the form of a
> template which follows:
>
> #include <strstream.h>
>
> template <class T> char_data * operator<<(char_data *ch, T msg) {
> ostrstream strout; // inherit ostream to get inserters
> strout << msg << ends; // insert message and NULL-terminate
> send_to_char(strout.str(), ch); // lock char* and send it
> strout.freeze(0); // unlock char* so class can clean up
> return ch;
> }
>
> Unfortunately, the compiler bitches about the fact that char_data is a
> struct rather than a class. Is there any way around this other than
> actually changing it into a class? Could I get away with just replacing
> "struct" with "class" in structs.h and adding the line "public:" at the
> top? If I go that way, I guess I might as well define
> char_data::send(). Obviously, I eventually want to protect all data
> members and provide access functions, but first things first. For now,
> I'd be happy ditching those sprintf(buf, ...)'s and coding:
>
> ch << "Brought to you by the numbers " << 4.7 << " and " << 47 << "\n\r"
> << "and the letter " << 'B' << "\n\r";
>
> -- Brian
>
>
> +------------------------------------------------------------+
> | Ensure that you have read the CircleMUD Mailing List FAQ: |
> | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
> +------------------------------------------------------------+
+------------------------------------------------------------+
| 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