Some messaging observations for the input code (below).
# include <ios>
# include <fstream>
# include <istream>
using namespace std;
void CommandLine(int argc, char** argv);
int main(int argc, char** argv) {
string a = "output.txt";
string* b = &a;
ofstream y;
y.open("output.txt", ios::in);
y.open( a, ios::in);
y.open( a.c_str(), ios::in);
y.open((*b).c_str(), ios::in);
y.open( a.c_str, ios::in);
return 0;
};
g++-4 x.cpp with suggested error messages and reasoning
x.cpp: In function 'int main(int, char**)':
x.cpp:12: error: no matching function for call to 'std::basic_ofstream<char,
std::char_traits<char> >::open(std::string&, const std::_Ios_Openmode&)'
/usr/lib/gcc/i686-pc-cygwin/4.3.2/include/c++/fstream:626: note: candidates
are: void std::basic_ofstream<_CharT, _Traits>::open(const char*,
std::_Ios_Openmode
) [with _CharT = char, _Traits = std::char_traits<char>]
x.cpp:15: error: no matching function for call to 'std::basic_ofstream<char,
std::char_traits<char> >::open(<unresolved overloaded function type>, const
std::_I
os_Openmode&)'
/usr/lib/gcc/i686-pc-cygwin/4.3.2/include/c++/fstream:626: note: candidates
are: void std::basic_ofstream<_CharT, _Traits>::open(const char*,
std::_Ios_Openmode
) [with _CharT = char, _Traits = std::char_traits<char>]
>>
1: error: open(arg1, ...) must be a C-string.
The existing message is indecisive in it's resolution. It might be
an acceptable idea to analyze expected input arguments and compare
them with actual arguments and then state a reason for failure based
on the actual argument(s) that failed. This is a labor since for
(example) if arg1 is valid for some overloaded functions but arg2 is
invalid for any functions, and then arg2 is valid for some functions
but arg1 is invalid for any function then there is a processing
overhead at diagnostic generation time. My argument is that one
function of a compiler is show the cause of failure in unambiguous
and clear terms.
2: error: open(arg1, ...) must be a C-string, and
error: a.c_str not a member of 'a'
The first failure is the inability to find a valid member of 'a'. This
leads to the second failure of being unable to find an overloaded open.
Nowhere is this clear from the messaging.
We have discussed the undue length of messaging before.
art