object member variables.

Discussion in 'C++' started by claire.bell1, Jul 23, 2003.

  1. claire.bell1

    claire.bell1 Guest

    Hi,
    Im making an othello game project and ive got to the point where the basic
    game is done, but i need to add an intro and some way of deciding who you
    play against.
    My current structure is:
    There is a main class othelloProgram which is created in the main method.
    I want the othelloProgram to be in 3 main states, intro, game or newgame.
    othelloProgram .: has an int variable state and the method SetState is
    passed to the objects it creates.
    To make a game an othelloProgram has 2 objects of type player and 1 of type
    othelloGame, othelloGame's constructor needs to be passed pointers to the
    players. othelloProgram also has an object of type intro.
    Initially I do not want the othelloGame or players to be created, their
    construction is dependant on the execution of the intro object, however the
    constructor forces me to make them which causes all kinds of errors.
    Also when intro eventually does run, i need to reconstruct the player and
    othelloGame objects.

    Is there any way to construct a class without constructing its member
    objects? Also how do you destroy and remake an object from a member method?

    Thanks for any help you can give,
    Vipa
     
    claire.bell1, Jul 23, 2003
    #1
    1. Advertising

  2. claire.bell1

    John Dibling Guest

    On Wed, 23 Jul 2003 16:05:58 +0100, "claire.bell1"
    <> wrote:


    >Is there any way to construct a class without constructing its member
    >objects?


    If you declare the member objects as pointers to objects, then you can
    just initialize the pointers to 0 instead of instantiating the
    objects.


    > Also how do you destroy and remake an object from a member method?


    Instead of this, try adding clear() and init() type methods to your
    class which reset & initialize the state of your object.

    </dib>

    John Dibling
    email: dib@substitute_my_full_last_name_here.com
    Witty banter omitted for your protection
     
    John Dibling, Jul 23, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dwok
    Replies:
    7
    Views:
    732
    Hal Rosser
    Mar 4, 2005
  2. Jian H. Li
    Replies:
    4
    Views:
    460
    Jonathan Higa
    Feb 13, 2004
  3. Replies:
    9
    Views:
    1,015
  4. blangela
    Replies:
    8
    Views:
    691
    Erik Wikström
    Sep 26, 2008
  5. K. Frank
    Replies:
    20
    Views:
    452
Loading...

Share This Page