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