Re: Do I need a singleton here? Or can I use std::move
"Jorgen Grahn" <grahn+nntp@snipabacken.se> wrote in message
news:slrnibs1mq.dlt.grahn+nntp@frailea.sa.invalid...
On Tue, 2010-10-19, Jim Langston wrote:
I am developing a font class for my opengl graphics library and I came
across a quandry. I have a font which is simply a value for font id and
wrapper code to load the font and kill it. Works fine, then I notice I
don't have a virtual destructor, nor any destructor at all. So I throw
in a
virtual destructor and call the code to unload the glfont. I run the
program, now no fonts are visible.
The problem is that my fonts are stored in a map by font name and the
font,
and of course std::maps along with most containers use copy.
Put differently: the problem is that you provided a copy constructor
and/or operator=() for something that wasn't really copyable. Always
consider if those should be disabled for new classes you write.
Actually: How can I use a non-copyable class in a standard container?
The problem is that the class can't be copied, at least as it is, because of
the destructor, but containers are loaded by copy. This problem is common
enough that, as I understand it, in C++0x the std containers will use
std::move instead of copy. Then I could simply disable the copy constructor
(create one and make it private).
I can't comment on the rest, except I don't see why you want run-time
polymorphism for a font handle class.
I don't.