Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > object member variables.

Reply
Thread Tools

object member variables.

 
 
claire.bell1
Guest
Posts: n/a
 
      07-23-2003
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


 
Reply With Quote
 
 
 
 
John Dibling
Guest
Posts: n/a
 
      07-23-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why can derived member function not access protected member of a baseclass object? blangela C++ 8 09-26-2008 03:24 PM
A reference to a hash member? (to an object's member variable) A. Farber Perl Misc 5 08-23-2008 07:00 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Differences between "class::member" & "object.member" Jian H. Li C++ 4 02-13-2004 10:54 AM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57