Thread: References to classes

  1. #1
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244

    References to classes

    Hi everyone. I have a huge problem(for one such as I this is really a problem). In my game I have a lot of subclasses that are magics. Example:
    Code:
    class Enchantament{
    //...
    };
    class Regeneration : Enchantament{
    //...
    };
    class Storm : Enchantament{
    //...
    };
    The creatures that has these magics only know a number, for example the magic regenaration has the number 2. But they need to cast this magic on another creature. The magic itself is the class that has a method that apply to the target creature.
    So... the owner of the magic needs do instantiate a new object from the desired magic on the target creature.
    My first thought was, somehow, out it all in an array, but that is impossible... Is that anyway that I can get a reference to a class and later create an object from it? Maybe rtti...
    Nothing more to tell about me...
    Happy day =)

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Does each creature have pointers to all kinds of magic?

    Suppose each creature has a method that receives the magic number from the "magic owner", and maybe uses a switch block to call the appropriate magic constructor.

    Then the magic owner can call that method of the target creature, sending it the magic number.

    Would that work?

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it kinda soudns like you should use structures instead... create a class with structures in it... give each character a copy of that class... and based on some user input (character type) just use some of the structures' members and the class' functions to pick them/pass them along...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    Actually, the fact that creature "has" that class, means that ih is under the effect of that class... I made an interface that send all the correct event to all the registered classes from that creature, so the effect could be activated... my fault! Because this is very complicated to explain here, so Iīll try to change my question as best as I can... how can I construct a class whitout calling the constructor? for example, using pointers to functions...
    Code:
    class T{
      T(){}
    };
    class W{
      W(){}
    };
    
    //declares an array of functions
    static void (*array[])()={ T::T , W:: W } // "assing" the pointers
    This is s little impossible I think, but that is the idea...
    Anyway, I think that this kind of thing itīs too "complex", maybe I should use a big case... Itīs not the most ellegant solution, but it works
    Nothing more to tell about me...
    Happy day =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  2. references to function in classes
    By Chrip in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2007, 11:39 AM
  3. References vs Pointer vs copying and storing stuff in classes
    By Monkeymagic in forum C++ Programming
    Replies: 20
    Last Post: 09-01-2006, 09:40 AM
  4. References in classes
    By tigs in forum C++ Programming
    Replies: 5
    Last Post: 08-10-2004, 06:30 PM
  5. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM