I have a class which has a friend function declared and defined inside the class and I'm calling this function from another function within the class. Clang compiler (3.3) complains for undeclared identifier for the friend function. I have compiled this code with MSVC and gcc and it works on both compilers but now with Clang port I'm getting this problem. Here's a simplified example case of the problem:
class foo
{
friend void bar() {}
void asd() {bar();}
};
In Clang I get: error : use of undeclared identifier 'bar'
. If I declare/define pla() outside the class, it works fine, but I have some macros which force me to define the function within the class. Is this some known issue in Clang or is Clang somehow more pedantic about the C++ name lookup while still conforming the C++ standard? Is there some known workaround for it while defining/declaring the function within the class?
bar()
supposed to be a member of classfoo
? Is there any other declaration ofbar()
? – Disputantfoo
, why does it need to befriend
? Just declare itstatic
. – Disputantfoo
as a friend function iffoo
needs to call (or otherwise access) private member functions (or data) in the class. But for the member functionasd
to callfoo
, all you need is a prototype offoo
before the class. – Skinnerfoo
. I guess I simplified the example a bit too much, sorry. I think I can actually move the friend function definition outside to solve this problem and just define it as a friend function within the class definition. – Langue