CObList::CObList
CObList( int nBlockSize = 10 );
参数:
nBlockSize | 扩展列表所需的内存分配的粒度大小。
|
说明:
构造一个空CObject指针列表。当列表增大后,以nBlockSize为单位分配内存。若内存分配失败,那么将产生CMemoryException。
示例:
下面列出CObject派生类CAged,它用于所有收集示例中:
// Simple CObject-derived class for CObList examples
class CAge : public CObject
{
DECLARE_SERIAL( CAge )
private:
int m_years;
public:
CAge() { m_years = 0; }
CAge( int age ) { m_years = age; }
CAge( const CAge& a ) { m_years = a.m_years; } // Copy constructor
void Serialize( CArchive& ar);
void AssertValid() const;
const CAge& operator = ( const CAge& a )
{
m_years = a.m_years; return *this;
}
BOOL operator==(CAge a)
{
return m_years == a.m_years;
}
void* operator new(size_t nSize);
void* operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
void operator delete(void* p);
void operator delete(void* p, LPCSTR lpszFileName, int nLine);
#ifdef _DEBUG
void Dump( CDumpContext& dc ) const
{
CObject::Dump( dc );
dc << m_years;
}
#endif
};
下面为CObList构造函数用法的例子:
CObList list( 20 ); // List on the stack with blocksize = 20.
CObList* plist = new CObList; // List on the heap with default blocksize.