I have an object that requires a slightly different construction wether it's instance is staticly or dynamically allocated. The object should only have a single default constructor. So having two constructors, one for each case, and having the user explicitly select the proper constructor is out of the question.
Is there any proper way to acheive this?
That's how I do this at the moment: I overload the new operator for that object, malloc the memory, and use the returned pointer as a pointer to the (yet un-initialized) instance, and set a specific data member of the object to some magic-value. Then, within the consutrctor, I check the value of the member. If it's the magic-value, then the object is 99.9% dynamically allocated.
This method haven't yet failed for me under either relase and debug modes, however, it seems like a terrible hack.