自定义了结构体如下
typedef struct NODEPOINT
{
int x;
int y;
double nPower;
CList<int,int> NeighborList;
CList<int,int> SleepNodeList;
CList<int,int> tempLOW;
CList<int,int> tempHIGH;
BOOL NodeStatus;
BOOL CoverStatus;
BOOL StatusCheck;
NODEPOINT::NODEPOINT()
{
x = 0;
y = 0;
nPower = 1.0;
NodeStatus = FALSE;
CoverStatus = FALSE;
StatusCheck = TRUE;
}
NODEPOINT::NODEPOINT(const NODEPOINT& s)
{
x = s.x;
y = s.y;
nPower = s.nPower;
NodeStatus = s.NodeStatus;
CoverStatus = s.CoverStatus;
StatusCheck = s.StatusCheck;
}
NODEPOINT operator=(const NODEPOINT& nodey)
{
NODEPOINT nodex;
nodex.x = nodey.x;
nodex.y = nodey.y;
nodex.nPower = nodey.nPower;
nodex.NodeStatus = nodey.NodeStatus;
nodex.CoverStatus = nodey.CoverStatus;
nodex.StatusCheck = nodey.StatusCheck;
return nodex;
}
}NodePoint; 上面定义了缺省构造函数,拷贝构造函数,重载了运算符=,现在想把结构体对象加到CArray中CArray<NodePoint,NodePoint&> NodeArray; NodeN.x = j;
NodeN.y = k;
NodeN.nPower = 1.0;
NodeN.NodeStatus = TRUE;
NodeN.CoverStatus = FALSE;
NodeN.StatusCheck = FALSE;
NodeArray.Add(NodeN);
......j,k为一些变量值,之前已经获得了值
可现在这么加进数组后,然后我再取出来,发现存入的结构体的值不对NodeN = NodeArray.GetAt(0);
cout << NodeN.x <<" "<< NodeN.y <<endl;这里输出0,0,单步调试,发现赋值成功了的,就是Add加入好像没有加对,不知为什么?
希望各位能帮忙看看,谢谢
typedef struct NODEPOINT
{
int x;
int y;
double nPower;
CList<int,int> NeighborList;
CList<int,int> SleepNodeList;
CList<int,int> tempLOW;
CList<int,int> tempHIGH;
BOOL NodeStatus;
BOOL CoverStatus;
BOOL StatusCheck;
NODEPOINT::NODEPOINT()
{
x = 0;
y = 0;
nPower = 1.0;
NodeStatus = FALSE;
CoverStatus = FALSE;
StatusCheck = TRUE;
}
NODEPOINT::NODEPOINT(const NODEPOINT& s)
{
x = s.x;
y = s.y;
nPower = s.nPower;
NodeStatus = s.NodeStatus;
CoverStatus = s.CoverStatus;
StatusCheck = s.StatusCheck;
}
NODEPOINT operator=(const NODEPOINT& nodey)
{
NODEPOINT nodex;
nodex.x = nodey.x;
nodex.y = nodey.y;
nodex.nPower = nodey.nPower;
nodex.NodeStatus = nodey.NodeStatus;
nodex.CoverStatus = nodey.CoverStatus;
nodex.StatusCheck = nodey.StatusCheck;
return nodex;
}
}NodePoint; 上面定义了缺省构造函数,拷贝构造函数,重载了运算符=,现在想把结构体对象加到CArray中CArray<NodePoint,NodePoint&> NodeArray; NodeN.x = j;
NodeN.y = k;
NodeN.nPower = 1.0;
NodeN.NodeStatus = TRUE;
NodeN.CoverStatus = FALSE;
NodeN.StatusCheck = FALSE;
NodeArray.Add(NodeN);
......j,k为一些变量值,之前已经获得了值
可现在这么加进数组后,然后我再取出来,发现存入的结构体的值不对NodeN = NodeArray.GetAt(0);
cout << NodeN.x <<" "<< NodeN.y <<endl;这里输出0,0,单步调试,发现赋值成功了的,就是Add加入好像没有加对,不知为什么?
希望各位能帮忙看看,谢谢
ElementAt返回引用
或直接用数组试试
{
NODEPOINT nodex;
..............
return nodex; //这里返回,为什么不行
}
{
CString strAppName;
DWORD dwAppStyle; MYSTRUCT()
{
strAppName = _T("");
dwAppStyle = 0;
} MYSTRUCT(MYSTRUCT &other)
{
*this = other;
} MYSTRUCT & operator = (MYSTRUCT& other)
{
strAppName = other.strAppName;
dwAppStyle = other.dwAppStyle; return *this;
}
};typedef CArray<MYSTRUCT, MYSTRUCT&>CMyStrcutArray;