TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BRIAN WOOD
from: KURT KUZBA
date: 1998-02-05 23:59:00
subject: more questions about new

BW> char *Enlarge(char *p)
BW> {
BW>    char *x=new char[20];
BW>    delete[] p;
BW>    return x;
BW> }
BW> void main()
BW> {
BW>    char *sz=new char[10];
BW>    sz=Enlarge(sz);
BW> }
BW> so far seems to work, but am I even on the right track?
   Sure. But why do you need a separate variable at all?
char *DimChar(char *pszP, int iLen = 19)
{
   delete []pszP;
   pszP = new char[iLen = 1];
   return pszP;
}
   Here you have the ability to enlarge your string to any
   size with a default value of 19, plus 1 for '\0'.
   The lack of a test for NULL on the delete is troublesome,
   however. You really should initialize a pointer to NULL
   if not initializing it otherwise, and then perform a test
   on it before attempting to delete. I'm coming from a C
   background though, so perhaps C++ has an exception for this
   of which I am not aware and would not be troubled by it.
> ] Let he among you without sin cast the first... OW! HEY!!....
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)

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™.