Thread: Can you Initialize all classes once with New?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    9
    @ Laserlight. I appreciate your response, I feel nervous as I am a newbie and hope that I explained the problem fully; I did not mention that I use base classes.

    The problem may be in the creation of my classes. I have several base classes for example an ArtBase(), a PodBase(), an IslandBase(), a WarriorBase(). Then there are team classes that have the vectors to iterate through each base class. For example the PodTeam() iterates through the PodBase class. . If I understand what you are saying is that when I use

    Code:
    std::vector<ArtItem>
    The information is preserved? Would that be correct of the <PodBase*> class below.

    So in this code below all the PodBase information is retained as long as the initialization is like this std::vector<PodBase*> m_Pods; //here I am not creating a new PodBase Object?

    However Do I still have to do the “new” as you see in this function SpawnPod() below continuously for each function to access the classes it needs it seems redundant(it must be me ?

    Code:
    Model*  m_pModel = new Model;
    	PierTeam* m_pPierTeam = new PierTeam;

    Here is the full function where you can see that I have to use new to create access to needed classes. And the use of std::vector<PodBase*> Is this the proper protocol or can I initialize all the classes I need in one place so that I do not have to do this in each function?

    Code:
    //------------------------- SpawnPod ---------------------------------
    //this places the first angel pod on the island
    //PodTeam->PlaceFisrtPodsOnIsland(RegionManager->GetGameLevel());  
    //------------------------------------------------------------------------
    int PodTeam::SpawnPod(int regionLevel)
    {
    	Model*  m_pModel = new Model;
    	PierTeam* m_pPierTeam = new PierTeam;
    	int spawnedPod = 0;
     
     std::vector<PodBase*>  m_Pods;
    	if(m_pModel->GetGameLevel() == 1)
    
    	{
    		if(m_pPierTeam->IsTherePodAtPierLocation(100) == false )
    		{
    		
    		std::vector<PodBase*>::iterator it = m_Pods.begin();
    
    			for (it; it != m_Pods.end(); ++it)
    		  {
    
    		  if ((*it)->GetRegionLocation()== regionLevel  && (*it)->GetAliveStatus()== 1)
    		
    			  {
    	
    				(*it)->SetAliveStatus(2);
    
    				(*it)->SetPierLocation(100);
    				
    				spawnedPod = (*it)->PodESPR();
    				std::cout << "This is the Pod ESPR Gw!!!" << std::endl; 
    				std::cout << (*it)->PodESPR() << std::endl; 
    
    			}					
    		}
    
    	}
    
    }
    		std::cout << "Spawn Pod Number!!!" << std::endl; 
    		return spawnedPod; 
    		std::cout << spawnedPod << std::endl; 
    
    }
    Thank you for your response

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by peacerosetx View Post
    Code:
    std::vector<ArtItem>
    This is not right. If you try to place any other object than ArtItem in there, it would slice the object, if the code would compile at all.

    The information is preserved? Would that be correct of the <PodBase*> class below.
    If it's a pointer, then information will be preserved.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

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