Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

EvilCrap

Vector not working?

This topic is 6112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi! in the msdn, it says that vector::clear() calls destructors, but in my code, it doesnt seem to be:
    
void main()
{
	vector<CBASE_ANIMAL*> vpba;

	CBASE_ANIMAL *pba = NULL;
	
	pba =(CBASE_ANIMAL*) new CCAT;
	vpba.push_back(pba);

	pba =(CBASE_ANIMAL*) new CDOG;
	vpba.push_back(pba);
	
	vector<CBASE_ANIMAL*>::iterator It;
	for( It = vpba.begin(); It != vpba.end(); It++)
		{
			(*It)->Act();
		}
	vpba.clear();  //should call destructors, but dont

	cout << vpba.empty ();  //true


}//main

    
!? this is my first vector program so maybe i am doing something wrong. i know the destructors arent being called cause they print out somethjing like "animal is dead". thanks! Edited by - evilcrap on December 29, 2001 9:22:28 PM Edited by - evilcrap on December 29, 2001 9:23:25 PM

Share this post


Link to post
Share on other sites
Advertisement
no it doesn''t. You''re misreading the documentation.

If you create a vector of objects, those objects will get correctly destructed. But if you create a vector of pointers, the only things that will get destructed will be the pointers themselves, and not the objects they point to.

Share this post


Link to post
Share on other sites
quote:
Original post by EvilCrap
so... i guess i got to go through the loop and manually call delete [] then.


I think that should be just "delete", unless the elements in your vector are pointers to dynamically allocated arrays created with new[].

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!