Thank you Cirilo. I am trying to be really careful here, that is why I am asking for more details. I would like to make the code simpler, so there are no more doubts about whether to use operator = or Copy() (for some classes it is exactly the same code).
For the scenario you described, there is EDA_ITEM::Clone() method.
Copy() is defined only for a few classes, and others are copied using
operator=, so it is a bit confusing to me.
Regards,
Orson
On 05/26/2016 01:23 AM, Cirilo Bernardo wrote:
> Be very careful; Copy() may exist because a Base Class copy constructor
> might not perform the desired task and an Abstract Class definitely cannot
> perform the desired task. For example:
>
> class A0; (abstract or base class)
> class A1 : public A0;
> class A2 : public A0;
>
> void bar( A0* var );
>
> void foo()
> {
> A1 a1;
> A2 a2;
>
> bar( a1 );
> bar( a2 );
> }
>
> bar( A0* bar )
> {
> // now we want a copy of *bar - how do we do that?
>
> // the typical solution:
> A0* newItem = bar->NewCopy();
> }
>
>
> On Thu, May 26, 2016 at 12:03 AM, Maciej Sumiński <[email protected]>
> wrote:
>
>> I am trying to understand the meaning of Copy() method defined for some
>> of BOARD_ITEMs. I would like to replace the method with operator= to
>> make the code clearer, and then give it consistent behavior. I have
>> noticed that Copy() implementations differ in:
>>
>> - clearing Pback/Pnext fields
>> - setting a new timestamp
>> - copying pointer to parent object
>>
>> I guess we should not change parent & DLIST related fields, as they are
>> expected to be already set to valid values (might be NULL for standalone
>> objects, but it is still OK). I suspect timestamp has to be set to a new
>> value to distinguish the objects.
>>
>> Regards,
>> Orson
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to : [email protected]
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help : https://help.launchpad.net/ListHelp
>>
>>
>
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp

