+ 1
What does 'new' do that malloc/realloc do not do ?
Today vs code gave me this warning: "moving an object of non-trivially copyable type ‘class vektor<int>’; use ‘new’ and ‘delete’ instead [-Wclass-memaccess]". Why does vs code encourage me to use new instead of realloc ? What does new do that realloc doesn't/can't do ??
5 Réponses
+ 4
Like malloc(), new allocates space in memory.
Unlike malloc(), new initializes the memory and calls the class constructor.
I am struggling to understand in what manner you were trying to use realloc() on an object pointer, and struggling even more to understand why. It would be more helpful if you link your source code and explain the thought behind what you were trying to do. Maybe there is a more conventional way to do it.
+ 3
We use use malloc to allocate new memory to store data while realloc is used to reassign memory to mostly add more space or memory to add data.
+ 2
What is the code that causes this warning?
What C++ standard are you using?
Is it your own `vektor` template class or `std::vector`?
0
Евгений true. I was using my vektor and the compiler gave me this warning
0
Ali_combination What about my other questions?