Solved
Reliable class design
Posted on 2000-02-27
Hi dudes,
I'm currently on the learning curve of C++. However, many years of regular C programming leave me with the notion that I may be up to some bad habits... I wonder if you could provide any suggestions...
I'm currently working on a simple hex dump class: It works, but is there a smarter, more bulletproof way of doing it? The way I've designed it is that it takes a constant pointer to a constant byte:
myDump.LookAt((reinterpret_cast<const char * const>(pBuffer)));
Pretty ugly, to say the least. Is it possible to, say, use void pointers to make the LookAt member function accept any type of pointer without the foul casting and no subsequent whining from the compiler?
In addition, the class has these two member functions:
void DumpClass::OutputHex(unsigned char *pszOutput, int nBytesToGet);
void DumpClass::OutputASCII(unsigned char *pszOutput, int nBytesToGet);
These take a pointer to a string and output the corresponding hex dump data to that string, eg.
const int nBytesToGet=16;
char outputbuff[64];
DumpClass myDump;
myDump.LookAt(pSomeLoc);
myDump.OutputHex(outputbuff, nBytesToGet);
It troubles me that it is up to the programmer to make sure that the output buffer is big enough to hold the dump output... What would be a better way?
Since this is really 2 questions, I've doubled the points...
Cheers