我該如何去複製一個struct
到另一個。目前,下面的代碼編譯時會在運行時崩潰。有一個更好的方法嗎?C++中的重複結構
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? – Far
什麼是'tripList'?你應該可以在循環中使用這個語句'Tripfeed [time] .push_back(tripList [trp])' –