+ 2
You should not combine new and realloc in C++. Use new and delete together , or malloc(), calloc(), free() together(C's way). Their allocators could be different and therefore may not result what you really want. Of course, you can use realloc(), don't use new and delete then. But it's more like a solution in C, not C++. https://stackoverflow.com/questions/33706528/is-it-safe-to-realloc-memory-allocated-with-new
5th Jan 2021, 12:52 PM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 1
Martin Taylor any idea why C++ provided 'new' in place of malloc/calloc but didn't provide an alternative to realloc?
5th Jan 2021, 11:32 AM
Sonic
Sonic - avatar
0
No. Array is fixed size. You can, however, create a new array with different size, and copy the entire array to the new one. Remember to delete the old array. Or better, use vector.
5th Jan 2021, 10:51 AM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar