Make wxRefCounter non copyable.

wxRefCounter copy ctor was wrong as the new object had the same reference
count as the old one instead of starting its life with reference count set to
1 as any new object should.

While we could fix its copy ctor, it seems to be better to forbid copying
wxRefCounter objects at all because the semantics of doing this is not obvious
and the compiler-generated copy ctor in the derived classes often doesn't do
what the code using it expects it to do, as was discovered by making
wxRefCounter non copyable: see the fixes in the previous commits.

To uncover all such bugs, make wxRefCounter and classes deriving from it non
copyable. If this uncovers more problems, they should be fixed by implementing
copying properly (and explicitly) in the derived classes.

Closes #12768.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66374 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-12-14 18:43:49 +00:00
parent f9b4d680d7
commit fd08ccd246
4 changed files with 25 additions and 2 deletions

View File

@@ -422,6 +422,12 @@ protected:
private:
// our refcount:
int m_count;
// It doesn't make sense to copy the reference counted objects, a new ref
// counter should be created for a new object instead and compilation
// errors in the code using wxRefCounter due to the lack of copy ctor often
// indicate a problem, e.g. a forgotten copy ctor implementation somewhere.
wxDECLARE_NO_COPY_CLASS(wxRefCounter);
};
// ----------------------------------------------------------------------------