🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Don Dewar Fri, 25 Jan 1991 11:48
Undeliverable Mail
#380
Author: Don Dewar
Date: Fri, 25 Jan 1991 11:48
71 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads