#include <iostream>
using namespace std;
int main()
{
char* MainBlock = new char[100];
char* SubBlock1 = new (MainBlock) char[20];
char* SubBlock2 = new (MainBlock) char [20];
cout << static_cast<void*>(SubBlock1) << " " << static_cast<void*>(SubBlock2);
}
Why do both the pointers in the code above have the same address? I expected SubBlock2 to be 20 bytes after SubBlock 1.
Does this mean I can allocate an endless number of pointers with placement new even though I only have 100 bytes?
How can I ensure that SubBlock6 will be a nullptr or out of bounds using placement new?