我對Java非常熟悉,並且允許在那裏使用。但是它看起來不像C++。嘗試分配valuesToGrab = updatingValues;時遇到「無效數組賦值」。C++將int數組賦給一個int數組,其大小相同
//these are class attributes
int updatingValues[361] = {0};
int valuesToGrab[361] = {0};
//this is part of a function that is causing an error.
for (unsigned int i=0; i < 10; i++) {
//this fills values with 361 ints, and num_values gets set to 361.
sick_lms.GetSickScan(values,num_values);
//values has 361 ints, but a size of 2882, so I copy all the ints to an array
//of size 361 to "trim" the array.
for(int z = 0; z < num_values; z++){
updatingValues[z] = values[z];
}
//now I want to assign it to valuesToGrab (another program will be
//constantly grabbing this array, and it can't grab it while it's being
//populated above or there will be issues
valuesToGrab = updatingValues; // THROWING ERROR
}
我不希望有通過updatingValues迭代和一個把它添加到valuesToGrab之一,但如果我有我會的。有沒有一種方法可以將它與C++分配到一個函數中?
感謝,
對於C風格數組[memcpy](http://www.cplusplus.com/reference/clibrary/cstring/memcpy/)或[memmove](http://www.cplusplus.com/reference/clibrary/cstring/memmove /) – Joe 2011-12-13 20:59:57
「修整」數組似乎完全沒有必要。修剪,然後複製,雙倍如此。 – 2011-12-13 21:01:16
你真的應該在C&C++中學習內存管理。 – 2011-12-13 21:57:19