[wx-dev] Copying semantics of various objects (wxValidator)

Vadim Zeitlin vadim at wxwindows.org
Sat Sep 2 16:28:13 PDT 2006


On Mon, 28 Aug 2006 20:37:41 +0100 "Luke A. Guest" <laguest at archangeli.demon.co.uk> wrote:

LAG> I looked at the following hierarchy in wxWidgets:
LAG> 
LAG> + wxValidator (provides the Clone() method but only copies the relevant
LAG>       wxValidator (and derived) fields) ->
LAG>   + wxEvtHandler (non-copyable - declared using the 
LAG>       "DECLARE_DYNAMIC_CLASS_NO_COPY" macro) ->
LAG>     + wxObject (copyable)
LAG> 
LAG> This brings me to the question, if I pass a validator to wxWindow,
LAG> inside wxWindow calls Clone() which makes a copy of the validator. Now,
LAG> because the wxEvtHandler class is non-copyable, what are the base
LAG> wxEvtHandler members pointing at in a copied validator derived instance?

 I think making validators copiable/clonable was a mistake. You probably
shouldn't support this at Ada level.

LAG> How can the event handler for this validator actually be used? Is it
LAG> ever used?

 Yes, the validators always get the first chance at processing the events
for the window they're associated with.

LAG> So, my conclusion has been, surely deriving a copyable object from a
LAG> non-copyable object is bad. In this instance (wxValidator) I cannot see
LAG> how this will actually work.

 This does work because actually wxEvtHandler can be copied without any
problems formally (i.e. C++ compiler doesn't have any problems with it).
But logically it doesn't make much sense IMHO.

 Regards,
VZ





More information about the wx-dev mailing list