home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / cplus / 1979 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.1 KB  |  50 lines

  1. Xref: sparky comp.std.c++:1979 comp.lang.c++:18758
  2. Path: sparky!uunet!racerx!rodb
  3. From: rodb@racerx.bridge.COM (Rod Burman)
  4. Newsgroups: comp.std.c++,comp.lang.c++
  5. Subject: Constants
  6. Summary: How do constant arrays work?
  7. Message-ID: <1223@racerx.bridge.COM>
  8. Date: 6 Jan 93 17:14:26 GMT
  9. Followup-To: comp.std.c++
  10. Organization: Bridge Information Systems
  11. Lines: 37
  12.  
  13. Hi netters I'm having a slight portability problem which is this
  14.  
  15. class    base { /* stuff */ }
  16. class    derv : public base { /* more stuff */ }
  17.  
  18. const    derv    array[2] = { { /* 0th element */ }, { /* 1st element */ } };
  19.  
  20. (I may have got this slightly wrong doing it from memory but, it is obvious
  21. (I hope) that I'm trying to set up an array of constants) derv has the appropriate
  22. constructor which uses a constructor in base) Now this all works fine with Borland C++
  23. but when I try with DEC C++ (VAX/VMS) it fails, it seems that Borland gives me:
  24.  
  25.     for (i = 0; i < number_of_elements; i++) {
  26.         derv(/* this = &array[i] */ /* constant stuff */);    // 'clever' constreuctor
  27.     }
  28. or equivalent done at compile time, DEC C++ does something more like:
  29.  
  30.     for (i = 0; i < number_of_elements; i++) {
  31.         derv(/* this = &array[i]);            // default constructor
  32.         derv(/* this = &temp */ /* constant stuff */);    // clever constructor
  33.         derv(/* this = &array[i], */ temp);        // copy constructor
  34.     }
  35.  
  36. I deduce this from the fact that if I make the default and copy constructors visible
  37. (i.e. not private) the thing will compile. I also deduce that one of three things is
  38. wrong:
  39.  
  40.     1)    I've done something silly and Borland C++ is just being kind to a moron
  41.     2)    DEC C++ is stupid since it's method is not only much less efficient it also
  42.         makes my code much more involved as each derv in my application gets immeadiately
  43.         places on a queue somewhere so I have to destruct both the default constructed
  44.         and temp ones or my queue has 3 * too many members
  45.     3)    DEC C++ is right (i.e. doing what is to be expected) in which case the ARM is wrong
  46.         since surely Borland is doing what one would expect? (Hence my post to comp.std.c++)
  47.  
  48. Anyone out there got an anwer?
  49.         thanks Rod.
  50.