Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How do I make a copy constructor? (inheritance?)

by Anonymous Monk
on Jul 09, 2002 at 08:49 UTC ( [id://180430]=note: print w/replies, xml ) Need Help??


in reply to How do I make a copy constructor? (inheritance?)

There is a potential other problem with your code, which I would like to pinpoint as you have talked about inheritance. If your copy method is called for a child of the Stuff class it will generate a Stuff object and not the a Child-Of-Stuff object. In order to avoid this you could bless to ref($self) you might considder it unlikely that a child class will not override the copy constructor, but reasonable applications are thinkable. (e.g.dispatching by class, Stuff is abstract/interface and you just add methods in your child classes etc.) And there is a not OO issue, what if you change the name of your class, you have to change all your bless statements... It is in general a good idea not to hardcode this kind of information.
  • Comment on Re: How do I make a copy constructor? (inheritance?)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://180430]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-23 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found