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

  1. Path: sparky!uunet!ogicse!hp-cv!sdd.hp.com!zaphod.mps.ohio-state.edu!ub!acsu.buffalo.edu!yli
  2. From: yli@acsu.buffalo.edu (Yanhong Li)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Bus error
  5. Message-ID: <BxKp0G.Hy6@acsu.buffalo.edu>
  6. Date: 11 Nov 92 22:26:39 GMT
  7. Article-I.D.: acsu.BxKp0G.Hy6
  8. References: <720906577snx@trmphrst.demon.co.uk> <BxJ1nK.B0y@acsu.buffalo.edu> <1992Nov11.183909.24097@cc.umontreal.ca>
  9. Sender: nntp@acsu.buffalo.edu
  10. Organization: State University of New York at Buffalo/Comp Sci
  11. Lines: 43
  12. Nntp-Posting-Host: sybil.cs.buffalo.edu
  13.  
  14. In article <1992Nov11.183909.24097@cc.umontreal.ca> nadeau@JSP.UMontreal.CA (Nadeau Jean-Claude) writes:
  15. >In article <BxJ1nK.B0y@acsu.buffalo.edu> yli@acsu.buffalo.edu (Yanhong Li) writes:
  16. >>#include <iostream.h>
  17. >>
  18. >>class T {
  19. >> public:
  20. >> int i;
  21. >> void foo() {cout <<"foooo\n";}
  22. >>};
  23. >>
  24. >>void main(){
  25. >>T *tt[3][5];
  26. >>
  27. >>tt[2][3]->i=1;
  28. >>}
  29. >    Well, another C (NOT C++) pitfall.  You've declare "tt" as an array
  30. >    of array of POINTER to T.  So there is memory for 15 pointers not
  31. >    for 15 objects of type T.  You'll have to reserve memory for those
  32. >    objects and INITIALIZE the pointers to the addresses of those blocks
  33. >    of memory.  Or declare "tt" like that (If it's possible):
  34. >
  35. >        T tt[3][5];
  36.  
  37. Well, in some circumstances, I can not declare tt as an array of T, because
  38. T has virtual member functions, and I may assign tt to a derived class of
  39. T. That's why I must use pointer.
  40.  
  41.  
  42. >
  43. >    It's better to learn C before trying to use C++ ;-)
  44. >
  45. >    A not so joking idea. ;-)
  46. >-- 
  47. >Jean-Claude Nadeau, ing.    <nadeau@ERE.UMontreal.CA>
  48. >Services informatiques        Tel. (514) 343-6111,ext 5234
  49. >Universite de Montreal        Fax  (514) 343-2155
  50.  
  51.  
  52. -- 
  53. ===============================================================================
  54. Yanhong Li                          716-838-6493(h)    645-3198(o)
  55. Dept. of Computer Science                       Good good study                
  56. SUNY at Buffalo, Buffalo, NY14260               Up up every day
  57.