Path: utzoo!attcan!uunet!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jarthur!uci-ics!gateway From: schmidt@zola.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.c++ Subject: Re: Why doesn't this program work on UNIX ? Keywords: binary search tree Message-ID: <26607DFD.19382@paris.ics.uci.edu> Date: 28 May 90 01:25:17 GMT References: <1990May25.013535.16930@cbnewsl.att.com> <26601546.25889@paris.ics.uci.edu> <23340@uflorida.cis.ufl.EDU> Reply-To: schmidt@zola.ics.uci.edu (Doug Schmidt) Organization: University of California, Irvine - Dept of ICS Lines: 40 In-reply-to: sml@beach.cis.ufl.edu (Shein-Fong Law) In article <23340@uflorida.cis.ufl.EDU>, sml@beach (Shein-Fong Law) writes: >The following program using binary tree to find out the frequency of >words entered from keyboard works o.k when I used Zortech C++. But it >does NOT work when I used g++ or Glockenspiel C++! The compilation is o.k. >But the last line to output the word frequency prints nothing. I found out >by using dbx that 'this' pointer in function bst_nodes::forall in file >'bst.cxx' was NULL and thus the main program output nothing. Can anyone >tell me how I can fix this problem to make it work properly?. Try changing the following line: >// operator[] - access function >int& count_arrays::operator[](char* s) >{ > register count_nodes *&t = (count_nodes *)* lookup(&tree, s); > if (t == NULL) { > cout << "inserting\n"; > t = new count_nodes(s);} > return t->count; >} int& count_arrays::operator[] (char* s) { count_nodes *&t = (count_nodes *&) *lookup ((bst_nodes **) &tree, s); ^ // note the additional & if (t == NULL) t = new count_nodes(s); return t->count; } This should make things work again! Doug -- The official language of San Marcos is Swedish. All boys | schmidt@ics.uci.edu under the age of sixteen years old are now sixteen years | office (714) 856-4043 old. Underwear must be changed every half hour. It will +---------------------- be worn on the outside, so we can check. -- `Bananas' by Woody Allen