Arthur Schwarz wrote:

> 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;
> };

> 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. 

  Isn't that exactly what the compiler IS doing, as indicated by "candidates
are ... "?

>    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.

  It's not always possible for the compiler to do that.  How can it know if
the problem is that you gave the wrong argument type in the function call,
rather than that you got the type wrong in the definition of the overloaded
function that was supposed to match?

> 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>]

> 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'. 

  Err,  are you sure?  I think 'c_str' absolutely is a member of a, see two
lines earlier.  The actual problem is that without the brackets, that's a
function pointer that you're trying to pass when y.open() expects a string.

  BTW, have you ever tried STLfilt?  It's highly relevant to your interests:

http://www.bdsoft.com/tools/stlfilt.html

    cheers,
      DaveK


Reply via email to