Article View: gnu.g++.help
Article #380Undeliverable Mail
From: Don Dewar
Date: Fri, 25 Jan 1991 11:48
Date: Fri, 25 Jan 1991 11:48
71 lines
2425 bytes
2425 bytes
I tried to send this directly to the person, but it failed. Please
put your address in your mail somewhere.
) Return-Path: <help-g++-request@prep.ai.mit.edu>
) Date: 21 Jan 91 05:52:08 GMT
) From: uunet!csc1.anu.edu.au!csc1!drw900 ("Drew R Whitehouse")
) Organization: Australian National University Supercomputer Facility
) Subject: help with "new" operator...
) Sender: uunet!prep.ai.mit.edu!help-g++-request
) To: help-g++@prep.ai.mit.edu
)
)
) I'm having trouble understanding the functionality of "new" -
) why does the following bit of code crash ? Wht isn't the value of p in
) the function being returned ? (Yes, I'm new to c++...)
)
) Any help appreciated.
) Drew.
)
) --------------------------------------------------------------
)
) #include <stream.h>
)
) class junk
) {
) private:
) int a;
) public:
) junk() { a = 42; }
) void print (char* mess) { cout << mess << a << "\n"; }
) };
)
) void allocate(junk*);
)
) main()
) {
) junk* jp;
) junk* jj = new junk;
)
) allocate(jp);
)
) jj->print("allocated in main() - ");
) jp->print("allocated by allocate() -");
) }
)
) void allocate (junk* p)
) {
) p = new junk;
I believe you problem is here. It should read :
p = new junk();
) p->print("allocated inside allocate() ");
) }
)
) -------------------------------------------------------------------------
+---------+
| Coral |
|@@@@@*@**|
|@@*@@**@@| Don Dewar
|*@@**@@@@| Coral Network Corporation, Marlborough, MA
|@***@@@@@| Internet: don@coral.com
|@@**@@@@@| Phone: (508) 460-6010
|*********| Fax: (508) 481-6258
|Networks |
+---------+
End of returned message
Technical Details
Message-ID:
<9101251148.AA15748@zardoz.coral.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!zardoz.coral.com!donShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!zardoz.coral.com!don From: don@zardoz.coral.com (Don Dewar) Newsgroups: gnu.g++.help,comp.lang.c++ Subject: Undeliverable Mail Message-ID: <9101251148.AA15748@zardoz.coral.com> Date: 25 Jan 91 11:48:56 GMT Sender: daemon@tut.cis.ohio-state.edu Followup-To: gnu.g++.help Organization: Gatewayed from the GNU Project mailing list help-g++@prep.ai.mit.edu Lines: 71