clintbellanger/flare — Issue #283: `TooltipData` violates the Rule of Three
Author: Sevis
Created: 2012-01-07 12:56:34+00:00
State: open

At the moment, `TooltipData` only defines a destructor and not an assignment operator or copy-constructor, meaning it violates the http://tinyurl.com/694gwf . This is means that making any copy of a `TooltipData` will cause both to eventually clean themselves up and die horribly.

The problem is that copies of `TooltipData`s are being made all over the code, and for some reason, things haven't gone horribly wrong yet. This could be due to the pointers being cleaned up after the copy (although `TooltipData tip(func_that_returns_tooltip());` should always leave `tip` pointing to a freed surface, which it doesn't seem to), or SDL doing some magic to prevent this, or the compiler optimising in some weird way that would lead to this working despite everything.

I'm not quite sure what it is that can be done. Not allowing `TooltipData`s to be passed around by value would be the first step, but I'm not sure if it would be enough: perhaps there should be a `SharedSurface` class that does reference counting, but I wouldn't use it for all surfaces as it would incur a possibly significant performance overhead. C++11 offers another solution with move semantics, but I don't think this is a big enough issue warrant switching.

[Rule of Three](http://tinyurl.com/694gwf)