class Scene {
std::auto_ptr<Hit> hit;
Hit* Cast() {
hit.reset(new Hit(params)); // Allocation here
return hit.get();
}
};
- Using placement new with a memory buffer that is part of the scene class. Pro: simple and efficient. Con: not RAII, makes code friable.
- Overloading operator new for the Hit class. Pro: completely transparent to the Scene class. Con: the hassle of defining a clean memory pooling system.
- Using an std::vector to wrap a placement new solution into a clean package. Pro: simple, efficient and clean. Con: gross misuse of a container.
- Using boost::variant
, as the above solution. Pro: simple, efficient and clean. Con: nonsensical int value.