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)'

解决方案 »

  1.   

    typedef CTypedPtrList<CPtrList,int> MyList;
    你要用链表是吧。
    typedef CList<CTypedPtrList,CTypedPtrList&> MyList;
      

  2.   

    正在学习使用CTypedPtrList这个类型指针链表呢,发现这个模板类的第二个参数用指针的时候就不出上面的错误,但是如果用一般的类型就出错。主要是想知道是不是必须用指针的,MSDN上给的是
    template< class BASE_CLASS, class TYPE >
    class CTypedPtrList : public BASE_CLASS
    也没说要用指针的。
      

  3.   

    好像明白了点,CTypedPtrList这个模板类好像是对几个类的包装,被它包装的好像都是对指针进行处理的。呵呵,反正没人回,把分给你吧。