HN user

WorksOnRobots

4 karma
Posts2
Comments5
View on HN
Cool C Programming 13 years ago

Exactly. char * a = 0; int * b = 0; a + 1 = a + sizeof(char) = 1

b + 1 = a + sizeof(int) = 4

Pass the address of the block of memory to the constructor along with your other arguments and perhaps the length of the memory block (to assert that sizeof(block) >= sizeof(object)). Then use a C-style cast to cast the block of memory to your class. Construct the object like normal and return the address.