【发布时间】:2016-06-28 14:55:09
【问题描述】:
我怎样才能将一个struct 复制到另一个。目前,以下代码可以编译,但在运行时不断崩溃。有没有更好的方法来做到这一点?
struct Trip
{
int startX;
int startY;
int endX;
int endY;
int suppress
};
struct Feedback
{
int startX;
int startY;
int endX;
int endY;
int suppress;
};
vector<Trip> tripList;
vector<Trip> TTMx[288];
TTMX[0] = &tripList;
vector<Feedback> Tripfeed[288];
for(time = 0; time < 288; time++){
for (int trp=0; trp < tripList.size(); trp++) {
Tripfeed[time][trp].startX = tripList[trp].startX;
Tripfeed[time][trp].startY = tripList[trp].startY;
Tripfeed[time][trp].endX = tripList[trp].endX;
Tripfeed[time][trp].endY = tripList[trp].endY;
Tripfeed[time][trp].suppress = tripList[trp].suppress;
}
}
【问题讨论】:
-
你有一个包含 288 个空向量的数组。要将元素添加到一个向量,请使用
push_back。 -
如何使用push_back向对象startX添加数据?
-
什么是
tripList?你应该能够在你的 for 循环中使用这个语句Tripfeed[time].push_back(tripList[trp]) -
如果我消除这个复制程序,我的主要代码运行良好。因此,我不得不假设问题必须与上述代码有关。