The code I referred is in the link -> http://upcoder.com/3/roll-your-own-vector In this example, in the copyrange method, they are using new operator like in the below code.
static void
copyRange(T* begin, T* end, T* dest)
{
while(begin != end)
{
new((void*)dest) T(*begin);
++begin;
++dest;
}
}
Can anyone explain how new() works in this context?
Can I write new (dest) T(*begin);
instead of new((void*)dest) T(*begin);
since dest is already a pointer to T. Why should I cast it back to void*
?