I've seen a class which is a class which is defined like this..
class StringChild : public StringBase
{
public:
//some non-virtual functions
static StringChild* CreateMe(int size);
private:
unsigned char iBuf[1];
};
The static factory function has the following implementation..
return new(malloc(__builtin_offsetof(StringChild ,iBuf[size]))) StringChild();
So as far as I understand it this function is using placement new to extend this class.
Is this safe only because there is only 1 member and it's allocated on the heap?