home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13132 < prev    next >
Encoding:
Internet Message Format  |  1992-08-31  |  1.2 KB

  1. Path: sparky!uunet!gatech!rutgers!rochester!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!sm86+
  2. From: sm86+@andrew.cmu.edu (Stefan Monnier)
  3. Newsgroups: comp.lang.c++
  4. Subject: Getting type info back !
  5. Message-ID: <YeckhJS00awJ0JJJV7@andrew.cmu.edu>
  6. Date: 1 Sep 92 06:19:01 GMT
  7. Organization: Junior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
  8. Lines: 32
  9.  
  10.  
  11. I would like to store different type of objects in a 'generic' structure,
  12. using the (void *)
  13. The problem I'm faced with is that of determining the real type of an 
  14. object after storing in that structure (when I take it back)
  15.  
  16. It is a quite general question.
  17. Given a class T2 subclass of T1 and objects o2 and o1 of type
  18. respectively T2 and T1, you can safely do
  19.  
  20. o1 = o2
  21.  
  22. as o2 is of type T1, too. But how can I decide if
  23.  
  24. o2 = o1
  25.  
  26. is safe ? of course just o1=o2; o2=o1 IS safe, but in a more general
  27. situation, it is not. Eiffel has for this special case:
  28.  
  29. o2 ?= o1 
  30.  
  31. If o1 is effectively of type T2 (and not only T1), then o2==o1, else, o2==NIL
  32.  
  33. Is there something equivalent in C++ ?
  34.  
  35.  
  36.     Stefan Monnier
  37.  
  38.  
  39. -----------------------------------------------------
  40. -- On the average, people seem to be acting normal --
  41. -----------------------------------------------------
  42.