home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19768 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.1 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!walter!porthos!delphinus!chw
  3. From: chw@bellcore.com (Charlie Woloszynski,MRE 2J-278,8295228,,27143)
  4. Subject: Question of scope
  5. Reply-To: chw@bellcore.com
  6. Organization: Bellcore
  7. Date: Fri, 22 Jan 93 18:45:58 GMT
  8. Message-ID: <1993Jan22.184558.21397@porthos.cc.bellcore.com>
  9. Sender: netnews@porthos.cc.bellcore.com (USENET System Software)
  10. Lines: 37
  11.  
  12.  
  13. A (novice) question about scope.
  14.  
  15.  
  16. I have a class Base from which I derive several additional classes, as in:
  17.  
  18. class Base 
  19.   virtual Draw(); 
  20.  
  21. class Derived1 : public Base 
  22.   virtual Draw(); 
  23.  
  24. I need to pass a pointer to an instance of one of these derived classes 
  25. to a function (so I can make use of the derived functions) like:
  26.  
  27.  
  28. void foo(Base *p) 
  29.   p->Draw(); 
  30.  
  31. Now I generally need to create the Derived classes only to pass them
  32. to foo.  I don't want these instances to exist after the call to foo.
  33.  
  34. Anyway, does the following call the destructor just after returning
  35. from the foo?
  36.  
  37.    foo(& Derived1());
  38.  
  39. Does it have any ugly portability problems? 
  40.  
  41. Charlie Woloszynski
  42. chw@bellcore.com
  43.