2 ms·
RAII isn't just about the destructor, though. It's about writing the constructor in such a way that you can always safely destroy the object. If you don't wri
by AnimalMuppet 2y ago
RAII isn't just about the destructor, though. It's about writing the constructor in such a way that you can always safely destroy the object. If you don't write the constructor right, RAII might become something you really hate, because it could blow up on you any time the destructor fires.
- akoboldfrying 2y agoI meant that it's wonderful to use RAII classes that others have developed, rather than implement RAII classes for others to use. But now that you mention it: >It's about writing the constructor in such a way that you can always safely destroy the object. I agree, but I see this as a good thing, even though it makes the class slightly harder to implement than it might be if responsibility for getting the object into a state safe for destruction is dumped on (or even shared with) the calling code. The latter approach requires programmer discipline at every use -- but you will only implement the class once, and probably use it many times.