TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BENJAMIN L MCGEE
from: JERRY COFFIN
date: 1997-08-15 10:23:00
subject: couple of ?`s

On (11 Aug 97) Benjamin L Mcgee wrote to All...
 BL> ...manifest is initialized by one of the following constructors...
 BL> manifest::manifest(){ 
 BL>      filename = new char[FILENAME_MAX]; 
 BL>      while (!select(filename, FILENAME_MAX - 1)); 
 BL>      mstreamp = new ifstream(filename); 
 BL> } 
 BL> manifest::manifest(const char* manfile){ 
 BL>      filename = new char[FILENAME_MAX]; 
 BL>      strncpy(filename, manfile, FILENAME_MAX - 1); 
 BL>      mstreamp = new ifstream(filename); 
 BL> } 
 BL> How do I handle errors in opening the ifstream?
exception handling was invented largely to deal with errors in ctors.
There's really no other clean method available.
 BL> Is it a good idea perhaps, to just allocate space for filename within 
 BL> the constructor and then handle everything else in a manifest::init() 
 BL> member?  That would seem redundant to me but perhaps overloading 
 BL> constructors is already redundant.
I would avoid this if at all possible.  It's nearly inevitable that if
you require a separate call to initialize the class that at least
occassionally somebody will forget to call it.  One of the major
strengths of C++ is its ability to ctors and ensure that as soon as an
object comes into existence, it WILL be initialized.  Separating the two
cripples this capability.
    Later,
    Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)

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