K
Kei
Hi!
I know this question has been asked numerous times, and I have read
previous posts, but I would like to ask anyway :/
From previous posts, I realise it's safe to return a string, like the
following class method:
std::string MyFileReader::getFileInfo(std::string path);
But when I look at other codes, people seem to have different styles
when declaring a function like above. For example
// --(1)-- pass by reference
int MyFileReader::getFileInfo(std::string path, std::string &theInfo);
// --(2)-- const class ref
int MyFileReader::getFileInfo(const std::string &path, std::string
&theInfo);
// --(3)-- use char*
int MyFileReader::getFileInfo(const char* path, std::string &theInfo);
The C++ FAQ Lite seem to endorse using "const SomeClass &classRef" to
strictly prevenet modification of the class.. (No. 2), but I don't see
why I should not use constant char*. Is char* evil? I coded in C so
I'm fairly comfortable with char*
I just want to know, what is the rationale of each use, and how do you
choose which to use?
Thanks in advance!
Kei
I know this question has been asked numerous times, and I have read
previous posts, but I would like to ask anyway :/
From previous posts, I realise it's safe to return a string, like the
following class method:
std::string MyFileReader::getFileInfo(std::string path);
But when I look at other codes, people seem to have different styles
when declaring a function like above. For example
// --(1)-- pass by reference
int MyFileReader::getFileInfo(std::string path, std::string &theInfo);
// --(2)-- const class ref
int MyFileReader::getFileInfo(const std::string &path, std::string
&theInfo);
// --(3)-- use char*
int MyFileReader::getFileInfo(const char* path, std::string &theInfo);
The C++ FAQ Lite seem to endorse using "const SomeClass &classRef" to
strictly prevenet modification of the class.. (No. 2), but I don't see
why I should not use constant char*. Is char* evil? I coded in C so
I'm fairly comfortable with char*
I just want to know, what is the rationale of each use, and how do you
choose which to use?
Thanks in advance!
Kei