关于CtypedPtrList的有关问题,帮忙解惑
关于CtypedPtrList的问题,帮忙解惑
template < class BASE_CLASS, class TYPE >
class CTypedPtrList : public BASE_CLASS
中的TYPE参数必须的指针类型吗?
为什么我没用指针类型出错了,测试代码:#include <afxtempl.h>
#include <iostream.h>
typedef CTypedPtrList <CPtrList,int> MyList;
void main()
{
MyList ml;
for (int i=0;i <10;i++)
{
ml.AddTail(i);
}
}
出错:
e:\microsoft visual studio\vc98\mfc\include\afxtempl.h(1616) : error C2664: 'struct __POSITION *__thiscall CPtrList::AddTail(void *) ' : cannot convert parameter 1 from 'int ' to 'void * '
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\microsoft visual studio\vc98\mfc\include\afxtempl.h(1616) : while compiling class-template member function 'struct __POSITION *__thiscall CTypedPtrList <class CPtrList,int> ::AddTail(int) '
------解决方案--------------------
typedef CTypedPtrList <CPtrList,int> MyList;
你要用链表是吧。
typedef CList <CTypedPtrList,CTypedPtrList&> MyList;
template < class BASE_CLASS, class TYPE >
class CTypedPtrList : public BASE_CLASS
中的TYPE参数必须的指针类型吗?
为什么我没用指针类型出错了,测试代码:#include <afxtempl.h>
#include <iostream.h>
typedef CTypedPtrList <CPtrList,int> MyList;
void main()
{
MyList ml;
for (int i=0;i <10;i++)
{
ml.AddTail(i);
}
}
出错:
e:\microsoft visual studio\vc98\mfc\include\afxtempl.h(1616) : error C2664: 'struct __POSITION *__thiscall CPtrList::AddTail(void *) ' : cannot convert parameter 1 from 'int ' to 'void * '
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\microsoft visual studio\vc98\mfc\include\afxtempl.h(1616) : while compiling class-template member function 'struct __POSITION *__thiscall CTypedPtrList <class CPtrList,int> ::AddTail(int) '
------解决方案--------------------
typedef CTypedPtrList <CPtrList,int> MyList;
你要用链表是吧。
typedef CList <CTypedPtrList,CTypedPtrList&> MyList;