TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BENJAMIN L MCGEE
from: BALOG PAL
date: 1997-08-15 03:09:00
subject: couple of ?`s

                            Hi, Benjamin L Mcgee!
On 11 Aug 97  15:38:00 you wrote to All
 BLM> class manifest {
 BLM> public:
 BLM>  manifest();
 BLM>  manifest(const char *filename);
 BLM>  ~manifest();
 BLM>
 BLM>  void report_name();
report_name() const; ???
 BLM>
 BLM> private:
 BLM>  char* select(char *filename, int len);
probably ... const char *filename .. is better
 BLM>  char      *filename;
 BLM>  ifstream  *mstreamp;
 BLM> };
 BLM> manifest::manifest(const char* manfile){
 BLM> filename = new char[FILENAME_MAX];
 BLM> strncpy(filename, manfile, FILENAME_MAX - 1);
If the given filename is long enough I think you'll end up with a not 0-
terminated string.
 BLM> mstreamp = new ifstream(filename);
 BLM> }
 BLM> How do I handle errors in opening the ifstream?
Probably the same way you handle all other errors associated with the stream.
You probably must supply some interface to ask or clear its status.
 BLM> Is it a good idea perhaps, to just allocate space for filename within
 BLM> the constructor and then handle everything else in a manifest::init()
 BLM> member?  That would seem redundant to me but perhaps overloading
 BLM> constructors is already redundant.
Er, I think moving common code to a single function is not redundant but
removes ill redundancy.
Overloading ctors is not redundant either but in your case I'd better use a
single ctor of form:
 BLM>  manifest(const char *filename = 0);
That serves for both of your ctors after you insert an if branch.
Paul
... Veni, Vidi, VCR--I came, I saw, I taped
--- OS/2 Warp
---------------
* Origin: The FlintStones' Cave in BedRock (2:371/20)

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