home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2797 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  55 lines

  1. Path: columba.udac.uu.se!chaph!t94dwi
  2. From: t94dwi@chaph.tdb.uu.se (Daniel Widenfalk)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Return types and virtual methods.
  5. Date: 5 Feb 1996 11:40:47 GMT
  6. Organization: Uppsala University
  7. Message-ID: <4f4qbv$q18@columba.udac.uu.se>
  8. NNTP-Posting-Host: chaph.tdb.uu.se
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hi all,
  12.  
  13. I was trying to create a "set" class this weekend. I tried to do this:
  14.  
  15. class Set {
  16.     public:
  17.     virtual    ~Set();
  18.  
  19.     virtual Set & operator=(const Set &) = 0;
  20.     virtual Set operator~() = 0;
  21.     ...
  22. };
  23.  
  24. class BitSet : public set {
  25.     public:
  26.         ~BitSet();
  27.  
  28.     BitSet & operator=(const BitSet &);
  29.     BitSet operator~();
  30.     ...
  31. };
  32.  
  33. As you can see, I want to be able to handle several diffrent types
  34. of sets the same way. Now to the problem. This doesn't work. I get
  35. the error-message in my .cc file: 
  36.  
  37. BitSet operator~();
  38. BitSet cannot create instance of abstract object. (Or something like it)
  39.  
  40. As I see it, I get two assignment operators. One for Set & and one for
  41. BitSet &. This make the Set & one undefined in BitSet and therefore
  42. BitSet is an abstract class. This makes the compiler barf when it gets
  43. to operator~, which
  44. 1) Tries to return an abstract class instance
  45. and
  46. 2) HAVE DIFFRENT return values.
  47.  
  48. Now, my question is. How do I fix this? I want to be able to have several
  49. diffrent representations of sets, but I want them to look the same to the
  50. user.
  51.  
  52. All help appreciated
  53. /Daniel Widenfalk
  54. t94dwi@student.tdb.uu.se
  55.