Copy construction of class instance object

Michael P. Soulier msoulier at storm.ca._nospam
Fri May 30 12:07:20 EDT 2003


On Wed, 28 May 2003 10:24:08 -0600, Steven Taschuk
<staschuk at telusplanet.net> wrote:
> Quoth Bror Johansson:
>> Is there a good/recommended way to emulate the copy constructor
>> classinstance creation (a la C++) in Python?
> 
> Why do you want to?
> 
> If memory serves (and I haven't used C++ in quite a while, so it
> might not), the copy constructor is used when you do, for example,
>     Foo a;
>     Foo b = Foo("args", "to", "normal", "constructor");
>     a = b;
> Then a and b are different objects, the one in a having been
> created by the copy constructor.

    C++ copy constructors are also used under the covers to pass an
object by value in a method or function call, something that you don't
typically want to do in Python, unless you do it explicitely. 

    Remember, implicit bad. Explicit good. 

    Mike

-- 
Michael P. Soulier <msoulier at digitaltorque.ca>, GnuPG pub key: 5BC8BE08
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix
HTML Email Considered Harmful: http://expita.com/nomime.html




More information about the Python-list mailing list