I have this simple C++ program:
#include <iostream>
struct obj {
friend int f(int);
void m(int x) { std::cout << "f(" << x << ") = " << f(x) << std::endl; }
};
int main() {
obj o;
o.m(21);
}
int f(int x) {
return 2*x;
}
If I compile with the GNU C++ compiler g++
, I get the error prog.cpp:7:55: error: 'f' was not declared in this scope
However, if I compile it with cl
(and /W4
) it compiles and executes fine.
I am not sure which compiler is correct.
friend int f(obj const&, int);
so ADL would have worked by adding that first parameter (even if it is a dummy parameter). – Diencephalon