TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: TOM TORFS
from: BRIAN WOOD
date: 1998-02-02 07:01:00
subject: returning char. after delete[]

 BW>    strcpy( psz, "Should I Do This???" );
 BW>    delete[] psz;
 BW>    return psz;
 TT> No, definitely not!
OK, that's three for three against, and I think I knew it was wrong
anyway.  What about a solution?  Would a global char * be the best way?
char *psz=0;
char *FuncToGetSomeString( int len )
{
   delete[] psz;
   char *psz = new char[len];
   strcpy(psz, "What do you think?");
   return psz;
}
 
L8r,
bw
... Now is the time for senseless bickering!
--- Blue Wave/DOS v2.20
---------------
* Origin: River Canyon Rd. BBS Chattanooga, Tn (1:362/627)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.