MFC里CList相关问题(基础)

来源:百度知道 编辑:UC知道 时间:2024/05/16 23:49:01
请问一下,这个,我看介绍说这个是类模板.
第一个参数是对象的指针,
第二个是指针指向的那个类型.
这些我都理解了.

然后,我想用这个,
CList<CLine,CLine> m_Line;
CLine为自己定义的类类型,派生于CObject类.
这句话哪地方有问题?

****************
报错如下:
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1064) : error C2664: 'struct __POSITION *__thiscall CList<class CLineQ,class CLineQ>::AddTail(class CLineQ)' : cannot convert parameter 1 from 'class CLineQ' to 'class CLineQ'
No copy constructor available for class 'CLineQ'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1566) : while compiling class-template member function 'void __thiscall CList<class CLineQ,class CLineQ>::Serialize(class CArchive &)'
080425_2View.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1064) : error C2664: 'struc

一般用到CList的时候,集合的对象参数用指针比较好,不必考虑对象复制的产生的数据、效率等各种问题,只是集合的对象创建需要在堆上,最后要删除
CList<CLine *, CLine *>

如果一定要使用对象,要定义对象的复制过程,
class CLine{
...
CLine(const CLine &){...}
CLine &operator=(const CLine &){...}
};
另外,类的定义最好这样写,第二个参数用引用传递提高调用效率
CList<CLine, const CLine &>

没定义拷贝构造函数CLine::CLine(&CLine)