1.举个例子来说:struct sBN
{  
   int a;
};CList<sBN,sBN&> BookList;
sBN a;
a.a = 0;
BookList.AddTail(a);
int b = BookList.GetHead().a;//这句可以;
int d = BookList.GetAt(0).a;//这句报错.
编译是通过的.
为什么GetAt()是他的函数却不能用??2.如果将上面的结构改成这样.
struct sBN
{  
   CStringArray a;
};
CList<sBN,sBN&> BookList;//编译的时候这句就错了.怎么解决这种嵌套问题?报错:
error C2582: 'sBN' : 'operator =' function is unavailable
while compiling class-template member function 'struct __POSITION *__thiscall CList<struct sBN,struct sBN&>::AddTail(struct sBN&)'以上.先谢谢了.

解决方案 »

  1.   

    int d = BookList.GetAt(0).a;//这句报错.
    因为GetAt的参数不是int类型,而是POSITION类型。所以你传递0是不对的。
    在CArray中,GetAt的参数是整型,表示索引(就是顺序)。但CList和CArray不一样。GetAt参数是POSITION,并不是简单的顺序号。
      

  2.   

    一个例子是这样的:
    POSITION pos = myList.GetHeadPosition();
    ASSERT(CString("ABC") == myList.GetAt(pos));
      

  3.   

    CList 的GetAt函数参数是POSITION pos,不是序号。
    POSITION pos = BookList.GetHeadPosition();
    int d = BookList.GetAt(pos).a;
      

  4.   

    我有用POSITION 试过.不过我是直接POSITION pos = 0;所以没成功.
    有没有int转POSITION的方法.否则这样GetAt()还是没有意义的.先谢谢楼上的.
      

  5.   

    typedef struct tagsBN
    {  
       CStringArray a;
    }sBN,far *LPsBN;
    typedef CList<LPsBN,LPsBN> CBookList;
    CBookList BookList;
    ...
    ...
    应该OK
      

  6.   

    int转POSITION的方法:
    int d = BookList.GetAt(BookList.FindIndex(0));
      

  7.   

    2.如果将上面的结构改成这样.
    struct sBN
    {  
       CStringArray a;
    };
    CList<sBN,sBN&> BookList;//编译的时候这句就错了.
    ===============
    以上错误不是嵌套问题。请你仔细读一下错误信息。错误原因是CStringArray类没有实现=操作符,所以你后面的程序CStringArray b = BookList.GetHead().a;这句话编译无法通过。
      

  8.   

    我有用POSITION 试过.不过我是直接POSITION pos = 0;所以没成功.
    有没有int转POSITION的方法.否则这样GetAt()还是没有意义的.先谢谢楼上的.用Find或者FindIndex来获取对应索引的POSITION
      

  9.   

    smileconfess() 你的方法正确.
    happyparrot(快乐鹦鹉) 如你所说的.你们好牛啊.呵呵
      

  10.   

    MS 搞这些东西 晕了一大片
    STL库 想怎么用就怎么用
    清晰多了