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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!utcsri!newsflash.concordia.ca!IRO.UMontreal.CA!CC.UMontreal.CA!nadeau
  3. From: nadeau@JSP.UMontreal.CA (Nadeau Jean-Claude)
  4. Subject: Re: Bus error
  5. Message-ID: <1992Nov11.183909.24097@cc.umontreal.ca>
  6. Sender: news@cc.umontreal.ca (Administration de Cnews)
  7. Organization: Universite de Montreal
  8. References: <720906577snx@trmphrst.demon.co.uk> <BxJ1nK.B0y@acsu.buffalo.edu>
  9. Date: Wed, 11 Nov 1992 18:39:09 GMT
  10. Lines: 29
  11.  
  12. In article <BxJ1nK.B0y@acsu.buffalo.edu> yli@acsu.buffalo.edu (Yanhong Li) writes:
  13. >#include <iostream.h>
  14. >
  15. >class T {
  16. > public:
  17. > int i;
  18. > void foo() {cout <<"foooo\n";}
  19. >};
  20. >
  21. >void main(){
  22. >T *tt[3][5];
  23. >
  24. >tt[2][3]->i=1;
  25. >}
  26.     Well, another C (NOT C++) pitfall.  You've declare "tt" as an array
  27.     of array of POINTER to T.  So there is memory for 15 pointers not
  28.     for 15 objects of type T.  You'll have to reserve memory for those
  29.     objects and INITIALIZE the pointers to the addresses of those blocks
  30.     of memory.  Or declare "tt" like that (If it's possible):
  31.  
  32.         T tt[3][5];
  33.  
  34.     It's better to learn C before trying to use C++ ;-)
  35.  
  36.     A not so joking idea. ;-)
  37. -- 
  38. Jean-Claude Nadeau, ing.    <nadeau@ERE.UMontreal.CA>
  39. Services informatiques        Tel. (514) 343-6111,ext 5234
  40. Universite de Montreal        Fax  (514) 343-2155
  41.