home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!utcsri!newsflash.concordia.ca!IRO.UMontreal.CA!CC.UMontreal.CA!nadeau
- From: nadeau@JSP.UMontreal.CA (Nadeau Jean-Claude)
- Subject: Re: Bus error
- Message-ID: <1992Nov11.183909.24097@cc.umontreal.ca>
- Sender: news@cc.umontreal.ca (Administration de Cnews)
- Organization: Universite de Montreal
- References: <720906577snx@trmphrst.demon.co.uk> <BxJ1nK.B0y@acsu.buffalo.edu>
- Date: Wed, 11 Nov 1992 18:39:09 GMT
- Lines: 29
-
- 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];
-
- 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
-