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);
请问有没有简单的办法可以解决这个问题(不是重新编写成类,并为它定义拷贝构造函数)?
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);
请问有没有简单的办法可以解决这个问题(不是重新编写成类,并为它定义拷贝构造函数)?
重写ConstructElements()函数void AFXAPI ConstructElements<P>( P* pElements, int nCount )
{
......
}ps:其实struct跟class一样,也可以加入构造函数
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类。是不是有循环调用的嫌疑?
void operator=(tagTrainStopTime& t)
{
nStopAtCount=t.nStopAtCount;
nTrainIdxU=t.nTrainIdxU;
nTrainIdxD=t.nTrainIdxD;
arrStopTimesX.Copy(t.arrStopTimesX);
arrStopTimes.Copy(t.arrStopTimes); }