Skip to main content
gamedev.net
🔒 Locked

Vector not working?

Started by EvilCrap Dec 29, 2001 at 8:07 PM 2 replies 350+ views
Original Post
EvilCrap
EvilCrap
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
DrPizza
DrPizza
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.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;} /*** drpizza@battleaxe.net ***/
EvilCrap
EvilCrap
well that sucks.
so... i guess i got to go through the loop and manually call delete [] then.


Krunk
Krunk
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[].

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.