← Back to team overview

kicad-developers team mailing list archive

Re: Copy & operator=

 

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 <maciej.suminski@xxxxxxx>
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     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
>

Follow ups

References