home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!news.forth.gr!news.forth.gr!kilitzir
- From: kilitzir@antigone.csi.forth.gr (Xristos Kilitzirakis)
- Newsgroups: comp.lang.c++
- Subject: yagh!(yet another hard g++ (problem))
- Date: 12 Nov 1992 14:28:08 +0200
- Organization: Institute of Computer Science, FORTH Hellas
- Lines: 54
- Message-ID: <kilitzir.721570562@news.forth.gr>
- NNTP-Posting-Host: antigone.csi.forth.gr
-
- Suppose the following program :
- ----------------------
-
- #include <ostream.h>
- class base {
- int ss;
- public:
- virtual show() { cout <<"bbb ";}
- };
-
- class derived:public base {
- int ff;
- public:
- virtual show(){cout << " dddd";}
- };
- //-------------
- base f1()
- {
- derived d;
- return d;
- }
- //------------
- derived f2()
- {
- derived d;
- return d;
- }
- //-----------
- main()
- {
- base x = f1();
- x.show();
- x = f2();
- x.show();
- base x2 = f2(); // Compiler error
- x2.show();
- }
- -------------------------
- 1.(compiled under g++ with unknown version).
- Now, there's a compiler error in line "base x2 = f2()" - YET the
- statement "x = f2();" IS CORRECT!Any comments ?
- 2.What do you expect for the program to write ???
- answer --> bbb bbb !
- Is that also correct ???
-
-
- XXXristos K.
-
-
- mail yr e-mail at
- kilitzir @csd.uch.gr
- kilitxir@csi.forth.gr
-
- "I love making people crazy"
-