Thread: Can you Initialize all classes once with New?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    Question

    @LaserLight your help is very insightful your time is appreciated!

    When you say "base class", you mean "class that models a single object" rather than "class at the base of a hierarchy", right?
    Actually it is the bottom of the hierarchy, you put that nicely. What i mean is that the PodBase has the Pods Id number, their health points, the amount of time that they are alive, their reaction to warriors. The PodTeam() class is then able to group the PodBaseClass of pods through functions that have iterators. The PodTeam() can then access podsOnIsland(), or PodsAliveWithRedPoints(), PodsGoodHealth() etc.

    It is true that you are not creating a new PodBase object. You are creating a new std::vector<PodBase*> that is local to the member function. If you have a member variable named m_Pods, that variable would be hidden by this local variable.
    So for example in the example below when I change the SetAliveStatus(2); or the
    SetPierLocation(100); where (*it) is from the std::vector<PodBase*> (above), even if another function of this same PodTeam class creates another std::vector<PodBase*> m_Pods and accesses it with m_Pods the settings will be preserved from this earlier function since I am not creating a new PodBase object correct?

    Code:
    			(*it)->SetAliveStatus(2);
    
    				(*it)->SetPierLocation(100);
    I can’t understand why it is easy to access another class without the new with the std::vector, and why you can’t do this somehow with a regular object. When I do the compiler complains. If I write in the header for class Foo() as a private or protected member this code below:

    Code:
    Model*  m_pModel;

    And created the new to intialize it correclty. Then tried to access m_pModel to access their function in a class FooTwo() function I would get Access violation issues that I did not initialize the object correctly , even though another class initilized it for me already( I am from a Java background so I get confused with the naming convention of classes and object ..thank you for your patience)

    I saw a game where someone initialized all the classes once in an initialization and they were able to access each object with a pointer, I have been trying to find that example and can’t. Perhaps they were only accessing the classes for that particular class object and not for all the objects in their project. So am I correct that you must create the “new” class for each class that has functions that another Class’ function needs to access is that correct?

    @Elysia Thank you for your prompt response.
    Last edited by peacerosetx; 06-30-2008 at 01:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  2. const arrays in classes.
    By anonytmouse in forum C++ Programming
    Replies: 6
    Last Post: 04-18-2004, 11:41 AM
  3. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM