Hello,

The same programming error gives very different diagnostic using member
function and stand-alone function:

$ cat err1.cc
struct C {
  static void f(char const*& p);
};

void b(char* p) {
  C::f(const_cast<char const*>(p));
}
$ cat err2.cc
extern void f(char const*& p);

void b(char* p) {
  f(const_cast<char const*>(p));
}
$ g++ -c err1.cc
err1.cc: In function 'void b(char*)':
err1.cc:6: error: no matching function for call to 'C::f(const char*)'
err1.cc:2: note: candidates are: static void C::f(const char*&)
$ g++ -c err2.cc
err2.cc: In function 'void b(char*)':
err2.cc:4: error: invalid initialization of non-const reference of type 'const 
char*&' from a temporary of type 'const char*'
err2.cc:1: error: in passing argument 1 of 'void f(const char*&)'
$

I think the error message for member function is too difficult to
understand, whereas those for stand-alone function is crystal-clear.

$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: [...]
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
$

-- Sergei.

Reply via email to