• Welcome to Valhalla Legends Archive.
 

Structures and inheritence

Started by Arta, February 19, 2004, 03:04 AM

Previous topic - Next topic

Arta

I didn't want to have to go through another pointer - this has to remain compatible with existing code.

Kp

Quote from: Arta[vL] on February 21, 2004, 05:32 AM
I didn't want to have to go through another pointer - this has to remain compatible with existing code.


struct User {
   char name[16]; /* user's name, known to everyone */
};
struct LocalUser {
   User blah; /* interserver data */
   unsigned local_data_item1; /* add more as needed */
};


Thus, no pointers, and it does as Adron suggested.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Arta

With that, you'd have to do:


Local->User.name


to get to name. I want to be able to do


Local->name


in order to remain compatible with existing code.

iago

Quote from: Arta[vL] on February 21, 2004, 12:56 PM
With that, you'd have to do:


Local->User.name


to get to name. I want to be able to do


Local->name


in order to remain compatible with existing code.

I'd imagine you could override operator-> if you wanted to.  Although I've never tried overriding that one :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Eibro

Icky icky, but it'd probably work
struct User {
   char name[16]; /* user's name, known to everyone */
   operator char*() { return name; }
};

Eibro of Yeti Lovers.

Kp

Quote from: Arta[vL] on February 21, 2004, 12:56 PMWith that, you'd have to do:


Local->User.name


to get to name. I want to be able to do


Local->name


in order to remain compatible with existing code.

Yes, it would require a change.  However, unless you use really eww variable names, it ought to be pretty easy to come up with substitution patterns that can do all the renaming for you.  For instance, s/name/User.name/g. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Adron

Quote from: Kp on February 21, 2004, 06:46 PM
Yes, it would require a change.  However, unless you use really eww variable names, it ought to be pretty easy to come up with substitution patterns that can do all the renaming for you.  For instance, s/name/User.name/g. :)

Or simply #define servinfo_name User.user_name a la s_addr.