home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16151 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.2 KB  |  65 lines

  1. Path: sparky!uunet!mcsun!news.forth.gr!news.forth.gr!kilitzir
  2. From: kilitzir@antigone.csi.forth.gr (Xristos Kilitzirakis)
  3. Newsgroups: comp.lang.c++
  4. Subject: yagh!(yet another hard g++ (problem))
  5. Date: 12 Nov 1992 14:28:08 +0200
  6. Organization: Institute of Computer Science, FORTH Hellas
  7. Lines: 54
  8. Message-ID: <kilitzir.721570562@news.forth.gr>
  9. NNTP-Posting-Host: antigone.csi.forth.gr
  10.  
  11. Suppose the following program :
  12. ----------------------
  13.  
  14. #include <ostream.h>
  15. class base {
  16.               int ss;
  17.         public:
  18.         virtual show() { cout <<"bbb ";}
  19. };
  20.  
  21. class derived:public base {
  22.         int ff;
  23.           public:
  24.         virtual show(){cout << " dddd";}
  25. };
  26. //-------------
  27. base f1()
  28. {
  29. derived d;
  30. return d;
  31. }
  32. //------------
  33. derived f2()
  34. {
  35. derived d;
  36. return d;
  37. }
  38. //-----------
  39. main()
  40. {
  41. base x = f1();
  42. x.show();
  43. x = f2();
  44. x.show();
  45. base x2 = f2(); // Compiler error
  46. x2.show();
  47. }
  48. -------------------------
  49. 1.(compiled under g++ with unknown version).
  50. Now, there's a compiler error in line "base x2 = f2()" - YET the 
  51. statement "x = f2();" IS CORRECT!Any comments ?
  52. 2.What do you expect for the program to write ???
  53. answer --> bbb bbb !
  54. Is that also correct ???
  55.  
  56.  
  57. XXXristos K.
  58.  
  59.  
  60. mail yr e-mail  at
  61. kilitzir @csd.uch.gr
  62. kilitxir@csi.forth.gr
  63.  
  64. "I love making people crazy"
  65.