返回值CMap<int, int, CFileInfo, CFileInfo> 
变为CMap<int, int, CFileInfo, CFileInfo> &

解决方案 »

  1.   

    大哥:
    我错了, 但是我反尔不理解“引用”的概念了, 请解释一下。(我以前做java的)
    另外, 分怎样加给你。
      

  2.   

    这个程序错误:
     是你的 class 'CMap<int,int,struct CFileInfo,struct CFileInfo>' 没有写一个拷贝构造函数.
    #define  CMap<int,int,struct CFileInfo,struct CFileInfo>  CFileInfoMap
     编写拷贝构造函数 : CFileInfoMap ::CFileInfoMap ( CFileInfoMap & )
     
      

  3.   

    错误提示不是说的很清楚吗, CMap没有提供copy constructor函数啊
    error C2558: class 'CMap<int,int,struct CFileInfo,struct CFileInfo>' : no copy constructor available而你的程序中  return m_OrgFpMap;
    它的实现要依赖于CMap的copy constructor函数.即将m_OrgFpMap拷贝一份作为返回值.
    我觉得你的返回值设计的不好,效率低. 原因就是要调用CMap的copy constructor函数,已经产生了结果,还要再复制一遍. 所以有两个方法供选择:
    1)为CMap<int,int,struct CFileInfo,struct CFileInfo>定义copy constructor函数.
    2)修改返回值类型. 例如改为指针型:
    CMap<int, int, CFileInfo, CFileInfo>* CEx01cDlg::getFileNameInDir(LPCTSTR lpName)
    在函数中new一个CMap<int, int, CFileInfo, CFileInfo>变量,然后将其返回.
      

  4.   

    to hillmans and prog_st(st) :  不能简单的返回值申明为CMap<int, int, CFileInfo, CFileInfo> & .虽然可以编译通过,除非你将m_OrgFpMap放到函数外申明为全局的.否则它本身是堆栈变量,返回引用时已经释放了.
      

  5.   

    谢谢各位!
    我好象明白了, windows 是32位, 所有的函数返回值都是地址方式,
    函数中声名的变量, 而且需要返回它, 可以声名为静态或全局。
      

  6.   

    error C2558: class 'CMap<int,int,struct CFileInfo,struct CFileInfo>' : no copy constructor available表明CFileInfo没有一个缺省的构造函数,所谓的Copy Constructor即缺省构造函数,没有参数的构造函数。因为在所有的模板类中,当要构建这种类型的对象时,都要先调用其缺省的构造函数。所以你应该为你的自定义类CFileInfo加上一个缺省的构造函数CFileInfo::CFileInfo();