I know there are better options, like a std::vector
or std::array
etc. In my case, I have to use a pointer to a dynamically allocated array because I'm learning the copy-and-swap idiom and it involves creating my own resource management class.
Say I have a following copy constructor for a resource handle class:
A(const A& other) : size(other.size), arr(size ? new int[size]() : nullptr) {
std::copy(other.arr, other.arr + size, arr);
}
It doesn't compile in Visual Studio (2013 Preview nor 2012 Express). The error I'm getting is:
Is it possible to use std::copy
in another way so that the compiler stops yelling at me? Or is it a better idea to manually copy the contents of the array using a simple loop like
for (int i = 0; i < size; i++)
arr[i] = other.arr[i];
P.S. I don't want to use any hacks/macros to disable warnings etc.