What is the meaning of this semantics(::new)?

1
2
3
4
5
template<typename T>
void copy_init(T src, void* dst)
{
  ::new(dst) T(src); //what is this line doing?
}


1
2
3
4
5
void copy_init_n(T src, void* dst, size_t n)
{
  for(size_t k = 0; k < n; ++k)
  ::new((void*)((char*)dst + k)) T(src[k]); //what is this line doing?
}


Thanks a lot
It is calling the global operator new.
::new(dst) T(src); That is placement new. The space was already reserved, and now you are constructing the object by copy.
It is used in vector (through an allocator), so you have a capacity (space reserved) and a size (number of objects).

T(src[k]); that is confusing. ¿wasn't T *src ?
If that were the case, you are copying an array.
Topic archived. No new replies allowed.