Consider the following code:
#include <iostream>
struct foo {
friend void bar(foo) {}
void foobar() {
std::cout << &bar << '\n';
}
};
int main() {
bar(foo{});
foo{}.foobar();
}
gcc gives me this error:
main.cpp: In member function 'void foo::foobar()':
main.cpp:7:23: error: 'bar' was not declared in this scope
std::cout << &bar << '\n'; // error
^~~
This is because it baris a friend function defined in the class itself, which makes it invisible in the global namespace. The only way to access it is through ADL, but I have not found a way to use ADL to get the address bar.
So my question is: how can I get the address bar? Is there any other way than to determine baroutside foo?
source
share