Hi
OzgurGul wrote:
* @param dir Variable to receive the newly allocated directory
string.
* @param name Variable to receive the newly allocated name string.
* @param ext Variable to receive the newly allocated extension
string.
*/
virtual void parseFilename(const char* fname,
char** dir,
char** name,
char** ext);
I reckon this is not your code, but notice however that in my opinion it's
poor design. parseFilename expects you to give a string containing a
filename as the first argument, followed by pointers to char pointers that
will hold the addresses of the corresponding dir/name/ext parts of that
filename upon successful return.
So you are expected to use it like that:
char *dir, *name, *ext;
MyClass mc; // default constructor available/reasonable?
mc.parseFilename("/usr/lib/libc.so", &dir, &name, &ext);
/* now dir points to a C-string containing the directory part, name to the
name and ext to a string giving the extension */
Problems with this:
- It's C-strings all over. C-strings aren't exactly bad, but they make code
error-prone and clumsy. Prefer std::string (declared in <string>)
- parseFilename accepts pointers to pointers where it had better take
references to these pointers: parseFilename("/file.ext", 0, 0, 0);
- parseFilename allocates memory, but obviously you have to deallocate it
(does MyClass offer any deallocation function for that purpose?). That's
bad because you don't know whether to use free or delete (or maybe
something completely different)
Markus