0

I was going over a cpp con video, and I couldn't understand how it worked. I understand what it is doing, but now how. I haven't seen these syntaxes before.

template<class T> inline void
allocator<T>::construct(pointer p, T const& val)
{
    ::new((void*) p) T(val);
}

The allocator decouples memory allocation and object creation, (unlike the new operator). So this is the construction part. So to construct an object a reference to an already constructed T object is necessary. That seems circular. What is the ::new((void*) p) T(val); line doing ? Also what is inline void doing ?

Where can I learn more about things like this in C++ ?

François Andrieux
  • 28,148
  • 6
  • 56
  • 87
nnrales
  • 1,481
  • 1
  • 17
  • 26

0 Answers0