I am currently working on programming a pool allocator. My question boils down to the following code:
template <typename T>
union myUnion {
T data;
myUnion<T>* nextUnion;
};
void someFunction(){
myUnion<T> mu;
T* t = new (std::addressof(mu.data)) T();
//some code
myUnion<T>* mu2 = reinterpret_cast<myUnion<T>*>(t);
}
Is the address of mu always the same as mu2?
T* t = new (std::addressof(mu.data)) T();
is probably not a good idea if there is any non-trivial constructor or destructor involved. – Ula