home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 20089 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.6 KB  |  36 lines

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