home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!spool.mu.edu!yale.edu!think.com!rpi!deweeset
- From: deweeset@ptolemy3.rdrc.rpi.edu (Thomas E. DeWeese)
- Subject: Re: Duplicate Object in Think C?
- Message-ID: <d!q2saf@rpi.edu>
- Nntp-Posting-Host: ptolemy3.rdrc.rpi.edu
- Organization: Rensselaer Polytechnic Institute, Troy, NY
- References: <white.724729120@sfu.ca> <1992Dec19.002858.299@physc1.byu.edu>
- Date: Sat, 19 Dec 1992 20:26:00 GMT
- Lines: 24
-
- In article <1992Dec19.002858.299@physc1.byu.edu> seth@physc1.byu.edu writes:
- >In article <white.724729120@sfu.ca>, white@fraser.sfu.ca (Steve White) writes:
- >> How do you duplicate an object without knowing its class? We would like
- >> to write something like
- >>
- >> r = duplicate( p );
-
- Well CObject has a Copy meathod. So you can simply define a Copy meathod
- for your subclass of the object, that copies it (it might be that the default
- meathod can figure the size of all objects thus you would not need to
- redefine it).
- If you don't use CObject as your base class, then simply add the meathod
- to your base class, (and possibly copy the code from CObject). And if you
- are not using a single base class for all of your objects, you should add one
- after all they all share the fact that they are in your application.
- Then simply cast all of the object to your base class before passing them
- in.
- If you have any more questions let me know. BTW None of this would be a
- problem if the world had decided to use a reasonable implementation of objects
- like Objective C, where an object knows what type it is.
- Thomas DeWeese
- deweeset@rdrc.rpi.edu
-
-
-