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)
|