TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: RENE HERMAN
from: KURT KUZBA
date: 1998-04-29 23:48:00
subject: Default constructor

RH>   For instance, I was wondering if it were safe to pass a
RH>   NULL pointer to strdup, which would allow me to write
RH>   something like
RH>   TExample::TExample(const char *s)
RH>   {
RH>     this->s = strdup(s);
RH>   }
RH>   without having to check for s being NULL first.
RH>   Neither Borland's online help nor Tom Swan's function
RH>   reference said one way or the other, so I had to dig
RH>   into the RTL source to find out it *wasn't* safe, at
RH>   least not on my compiler.
RH>   I'm assuming the standard would have explicitly told me so.
   I know this will sound silly, but why would you want to use
   strdup() in C++?? The string class IS safe, and easier to use.
   Where TExample.s is defined as a class of type String:
TExample::TExample(const char *s) { this->s = s; }
   It doesn't get any more simple than this.
   I know it's beside the point, which is documentation for
   the RTL functions, but the Class Libraries often provide
   safe, and often superior, support for many data functions.
> ] So far, nobody has ever wanted to ride the Unicorn twice....
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * 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™.