User:Ccw
Jump to navigation
Jump to search
Some class constructors and destructors are too complex
Proposed solution to [issue http://bugs.mtasa.com/view.php?id=4377]
Example of solution when applied to CClientEntity and CClientColModel:
Current base and concrete class declaration:
class CClientEntity
{
public:
CClientEntity ( ElementID ID );
virtual ~CClientEntity ( void );
...
class CClientColModel: public CClientEntity
{
public:
CClientColModel ( class CClientManager* pManager, ElementID ID );
~CClientColModel ( void );
...
Proposed base class declaration and definition:
class CClientEntity
{
protected:
CClientEntity ( ElementID ID );
virtual ~CClientEntity ( void );
virtual void PostConstruct ( void );
virtual void PreDestroy ( void );
public:
void Delete ( void );
...
void CClientEntity::PostConstruct ()
{
// Code from CClientEntity constructor moved here
}
void CClientEntity::PreDestroy ()
{
// Code from CClientEntity destructor moved here
}
void CClientEntity::Delete ( void )
{
PreDestroy ();
delete this;
}
Proposed concrete class declaration and definition:
class CClientColModel: public CClientEntity
{
public:
CClientColModel ( class CClientManager* pManager, ElementID ID );
~CClientColModel ( void );
virtual void PostConstruct ( void );
virtual void PreDestroy ( void );
public:
static CClientColModel* NewCClientColModel ( CClientStreamer * pStreamer, ElementID ID );
...
void CClientColModel::PostConstruct ()
{
__super::PostConstruct ();
// Code from CClientColModel constructor moved here
}
void CClientColModel::PreDestroy ()
{
// Code from CClientColModel destructor moved here
__super::PreDestroy ();
}
CClientColModel* CClientColModel::NewCClientColModel ( CClientStreamer * pStreamer, ElementID ID )
{
CClientColModel* pElement = new CClientColModel ( pStreamer, ID );
pElement->PostConstruct ()
return pElement;
}
Other changes required
Any occurrence of
new CClientColModel ( pStreamer, ID ); delete pElement;
is replaced with
CClientColModel::NewCClientColModel ( pStreamer, ID ); pElement->Delete ();
