They go onto discuss how the new and delete keyword are actually implemented
1 2 3 4 5 6
A* a = ::operatornew(sizeof(A));
a->A::A();
if ( a != 0 ) { // a check is necessary for delete
a->~A();
::operatordelete(a);
}
I understand the first line we are calling operator new to allocate memory with malloc as far as I know
but the next line is what I don't understand a->is calling A's constructor,I have never seen this syntax before and never knew it was possible to create an object like this?
It's pseudo syntax. For instance, you don't pass sizeof(A) to new in real C++.
Maybe it should have been written less like C++. In English:
1 2 3 4 5 6 7 8
operatornew:
Set an A pointer to newly allocated memory the size of A
Call A's constructor on the pointer.
Return the pointer.
operator delete:
If the given pointer is null, do nothing.
Otherwise, Call the destructor on the pointer. And free the allocated memory.
I didn't actually say you "can't", I said you "don't", but should have added "usually" in the sense that if you want an object you just use the type unless you're doing something "fancy".