What does openTextFile return if it doesn't return an errorMsg?
Also, your source code doesn't completely sync. Your code shouldn't even compile if that's actually the code. On line 3 of your first source file, it shows your class is called "OBJ" but your class is called "MYCLASS", so it should be
std::ifstream ifstream;
^^^even if that works, this is horrible. give it a variable name. I wonder if any of your problems are caused by using the type as a variable name.
passing in error message is silly if its just going to echo the input path. its not an error, but its weird/pointless.
something like:
if(ifstream.fail())
{
string s = "Failed to open: "+filePath ;
return s;
}
+ + P035Y::openTextFile returned <Error reading characters of string.> std::string
Sorry, but I'm failing to communicate properly.
I'm not talking about runtime. I'm just talking about a static analysis of the code itself.
Your openTextFile does not return anything if the failure branch is not reached. Not returning something from a non-void function is undefined behavior.
As an alternative to what jonnin said, you might want to return bool instead, and pass an error message as a reference parameter (this comes down to opinion/style, there is no right answer).
whereas embedding cout in the routine limits it to only console programs.
I don't normally go into all that for what is clearly homework, but its a good thing to put in the back of your head: decouple the UI from the "work", always (well, once you get past getting your feet wet, its not critical in your first course).
returning a string works too, but its more flexible to allow the user to make their own messages rather than try to make a canned one that attempts to work for every user later. Then the user has to trap your message and rewrite it if they don't like what you provided.