use of delete (class)
Having issues using a delete in another function to clear my new or anyone have any suggestions to just get rid of the use of new.
1 2 3 4 5 6 7 8 9
|
// Generate puppys
for( unsigned i=0; i<5; i++ )
{
ilovepuppys[i] = new CTBoneStake( );
ilovepuppys[i]->id = i;
ilovepuppys[i]->Parents = this;
ilovepuppys[i]->newlypuppys = new boost::thread( boost::bind( &CTboneStake::Start, ilovepuppys[i] ) );
}
|
My header file
1 2 3 4 5 6 7 8 9 10 11
|
class CTBoneStake
{
private:
public:
void Start( );
class CBaseperson* Parents;
unsigned id;
boost::thread* newlypuppys;
};
|
and say something like this
1 2 3 4
|
CNewPlayer* CNewParents::CreateNewPuppy( )
{
return new Clilpuppy( );
}
|
header code to that
1 2 3 4 5 6
|
class CNewPlayer : public CTBoneStake
{
public:
virtual CNewPlayer* CreateNewPuppy( );
};
|
ilovepuppys.push_back( CTBoneStake(K,this,&CTboneStake::Start) );
the point is to use boost not really wanting to use push_back..
Try making a constructor and using a reference:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
class CTBoneStake
{
public:
void Start();
CTBoneStake(boost::thread &newlypuppies) : newlypuppys(newlypuppies)
{
//
}
CBaseperson* Parents;
unsigned id;
boost::thread &newlypuppys;
};
|
If you must still use a pointer for whatever random reason, then consider a destructor:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
class CTBoneStake
{
public:
void Start( );
class CBaseperson* Parents;
unsigned id;
boost::thread* newlypuppys;
~CTBoneStake()
{
delete newlypuppys;
}
};
|
Last edited on
Topic archived. No new replies allowed.