Ticket #2146 (closed enhancement: fixed)

Opened 8 years ago

Last modified 4 months ago

Copy constructor for wxValidator

Reported by: hwiesmann Owned by:
Priority: low Milestone:
Component: GUI-generic Version:
Keywords: simple Cc: hwiesmann, abxabx
Blocked By: Patch: yes
Blocking:

Description

When implementing a new validator class the a new class has to
be derived from wxValidator. wxValidator requires to overload the
Clone function. A clone function is often implemented like:

wxObject* Clone(void) const {return new(*this);}

Therefore, the derived class has to implement a copy constructor.
Unfortunately, wxValidator does not have a copy constructor
implemented. Therefore, in the copy constructor of the derived
function, first, the default wxValidator constructor has to be called
and afterwards the copy function of wxValidator.
This looks very ugly. A copy constructor of wxValidator should
solve this issue.

Attachments

2146.patch download (0.7 KB) - added by oneeyeman 4 months ago.
Attempt to fix
2146.diff download (0.7 KB) - added by oneeyeman 4 months ago.

Change History

  Changed 8 years ago by abxabx

To which wxWidgets version this report refers? I see in CVS
Head there is Clone in wxValidator so can I close this bug or do
you have any further notes?

ABX

  Changed 8 years ago by abxabx

Hartwig,

I repost my question: To which wxWidgets version this report
refers? I see in CVS Head there is Clone in wxValidator so
can I close this bug or do you have any further notes?

ABX

  Changed 8 years ago by hwiesmann

Hi ABX,

indeed there is a clone function in wxValidator but what is needed is a
COPY constructor.
As I mentioned before there are some ways to work around this
shortcoming but they are neither efficient nor nice.

Hartwig

  Changed 17 months ago by oneeyeman

It looks like this bug still stands.
There is no copy constructor in wxValidator. But I guess it can be done differently.

Can this be closed?

follow-up: ↓ 6   Changed 17 months ago by vadz

  • keywords simple added
  • priority changed from normal to low
  • status changed from new to confirmed
  • type changed from defect to enhancement

It would indeed make sense to add a copy ctor to wxValidator, no idea why this was never done but it should be.

in reply to: ↑ 5   Changed 15 months ago by oneeyeman

Vadim,
Replying to vadz:

It would indeed make sense to add a copy ctor to wxValidator, no idea why this was never done but it should be.

Maybe because it uses wxDECLARE_NO_COPY_CLASS() macro?

Anyway do we want to remove the macro and implement copy constructor?

  Changed 15 months ago by vadz

Yes, this is exactly what I wrote in comment:5, didn't I? As an aside, I do know that it uses wxDECLARE_NO_COPY_CLASS() but its presence doesn't explain why is it there.

Changed 4 months ago by oneeyeman

Attempt to fix

  Changed 4 months ago by oneeyeman

  • patch set

Attached please find the implementation of this request.
Please review and apply.

  Changed 4 months ago by oneeyeman

Sorry forgot to mention: patch is generated based on rev. 73355

  Changed 4 months ago by vadz

2 problems:

  1. Copy ctor shouldn't copy static fields, this doesn't make any sense.
  2. Before the class didn't have neither copy ctor nor assignment operator, now it has both while it probably still shouldn't have the latter. I.e. wxDECLARE_NO_COPY_CLASS() should be replaced with wxDECLARE_NO_ASSIGN_CLASS() instead of being removed.

Changed 4 months ago by oneeyeman

  Changed 4 months ago by oneeyeman

Attached please find version 2 of this patch.

  Changed 4 months ago by VZ

  • status changed from confirmed to closed
  • resolution set to fixed

(In [73403]) Add copy constructor to wxValidator.

It can be useful for implementing Clone() in the derived classes.

Closes #2146.

Note: See TracTickets for help on using tickets.