BM> class manifest {
BM> public:
BM> manifest();
BM> manifest(const char *filename);
Better declare the 2nd constructor "explicit" to avoid silent
conversions.
BM> private:
BM> char* select(char *filename, int len);
This method could as well return bool, which would make its return
value clearer.
BM> manifest::manifest(const char* manfile){
BM> filename = new char[FILENAME_MAX];
BM> strncpy(filename, manfile, FILENAME_MAX - 1);
This will cause you problems: strncpy will not zero-terminate filename
if manfile has FILENAME_MAX - 1 characters. I'd suggest to use a
string class instead of your char *.
BM> How do I handle errors in opening the ifstream?
Depends on what class manifest is responsible for. Options include:
- do it the way the fstream classes do
- throw an exception (which will make it difficult to free the memory
referenced by filename if you don't change filename's type to string)
BM> Is it a good idea perhaps, to just allocate space for filename withi
BM> the constructor and then handle everything else in a manifest::init(
BM> member? That would seem redundant to me but perhaps overloading
BM> constructors is already redundant.
You could just use the 2nd constructor with a default argument if you
prefer:
manifest(const char *filename = 0);
and
manifest::manifest(const char* manfile){
filename = new char[FILENAME_MAX];
if (manfile)
{
strncpy(filename, manfile, FILENAME_MAX - 1);
*filename[FILENAME_MAX-1] = 0;
}
else
while (!select(filename, FILENAME_MAX - 1));
mstreamp = new ifstream(filename);
}
Thomas
---
þ MM 1.0 #0113 þ I don't care WHO you are! Get those reindeer off my roof!
---------------
* Origin: McMeier & Son BBS (2:301/138)
|