error C2664: 'Add' : cannot convert parameter 1 from 'struct tagTrainStopTime' to 'struct tagTrainStopTime'
        No copy constructor available for struct 'tagTrainStopTime'
typedef struct tagTrainStopTime
{
   int x1;
   int x2;
} P;
CArray<P,P> a;
P p1;
p1.x1=1;
p1.x2=2;
a.Add(p1);
请问有没有简单的办法可以解决这个问题(不是重新编写成类,并为它定义拷贝构造函数)?

解决方案 »

  1.   

    看看msdn,那里有说
    重写ConstructElements()函数void AFXAPI ConstructElements<P>( P* pElements, int nCount )
    {
    ......
    }ps:其实struct跟class一样,也可以加入构造函数
      

  2.   

    呵呵,你的情况似乎是应该重写CopyElements
      

  3.   

    我头都大了。哪位仁兄可不可以给我一个具体的思路。
    c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(443) : error C2582: 'tagTrainStopTime' : 'operator =' function is unavailable
    我在结构里自己写了两个构造函数
    typedef struct tagTrainStopTime//列车在各站的停站时间
    {
    int nStopAtCount;//经停车站
    //CString szTrainIdx;//车次
    int nTrainIdxU;//程序内部使用上行车次,从1,3,5计
    int nTrainIdxD;
    CArray<float,float> arrStopTimesX;//存储X坐标即时间
    CArray<CString,CString> arrStopTimes;
    tagTrainStopTime()
    {
    nStopAtCount=0;
    nTrainIdxU=0;
    nTrainIdxD=0;
    arrStopTimesX.SetSize(0);
    arrStopTimes.SetSize(0); };
    tagTrainStopTime(tagTrainStopTime& t)
    {
    nStopAtCount=t.nStopAtCount;
    nTrainIdxU=t.nTrainIdxU;
    nTrainIdxD=t.nTrainIdxD;
    arrStopTimesX.Copy(t.arrStopTimesX);
    arrStopTimes.Copy(t.arrStopTimes);
    };
    }TRAINSTOPTIMES;结构里先使用了CArray类。是不是有循环调用的嫌疑?
      

  4.   

    如果是重写copyelement函数,是在哪重写啊?在afxtempl.h里多加一个定义吗?
      

  5.   

    我重载了=操作符号,暂时通过了编译
    void operator=(tagTrainStopTime& t)
    {
    nStopAtCount=t.nStopAtCount;
    nTrainIdxU=t.nTrainIdxU;
    nTrainIdxD=t.nTrainIdxD;
    arrStopTimesX.Copy(t.arrStopTimesX);
    arrStopTimes.Copy(t.arrStopTimes); }
      

  6.   

    标准C++中 struct 和 class的 区别 仅仅是 默认 public 和private