Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!agate!e260-2d!c60c-2ca From: c60c-2ca@e260-2d.berkeley.edu (Andrew Choi) Newsgroups: comp.lang.c++ Subject: Re: Why doesn't a void* & parameter get modified in C++ 2.0? Keywords: ? Message-ID: <1990Apr14.053858.22262@agate.berkeley.edu> Date: 14 Apr 90 05:38:58 GMT References: <1208@wizard.dsg.tandem.com> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: c60c-2ca@e260-2d (Andrew Choi) Distribution: usa Organization: University of California, Berkeley Lines: 48 In article <1208@wizard.dsg.tandem.com> larry@wizard.dsg.tandem.com (Larry Wear) writes: >The following program works correctly using AT&T's cfront 1.2, >however it does not work correctly using Sun's cfront 2.0. The >NullIt method in the class go does not modify the pointer value >of name. I would like to know why. Thanks. > >#include >#include > >#define NULL 0 >typedef void* ANY; > >class bigFun >{ > public: > > void NullIt( ANY & pObject ) > { > pObject = NULL; > } >}; > >void main() >{ > bigFun go; > char * name = malloc(5); > > go.NullIt( (ANY)name ); > if ( name == NULL ) cout << "Success\n"; > else cout << "Failed\n"; >} > >-- >Larry Wear wizard!larry@Tandem.COM >Tandem Computers The reason is that a temporary variable will be created if the type of reference variable does not match exactly the type of its assigned value or if the assigned value is a literal. The cast really does not affect anything because it merely informs the compiler which conversion is to be used. ---------- Andrew Choi Internet Address: c60c-2ca Standard Disclaimer