A question about friend functions
- by Als
I faced a problem recently with a 3rd party library which generates classes from a xml. Here is a gist of it:
class B;
class A
{
void doSomething();
friend class B;
};
class B
{
void doSomething();
void doSomethingMore()
{
doSomething();
}
};
The compiler flags call to the function doSomething() as ambiguous and flags it as an compiler error. It is easy to understand why it gives the error.Class B being friend of class A, every member of class B has access to all the members of class A. Renaming of the either of functions resolved my problem but it got me thinking that shouldn't in this case the compiler should give a priority to the class's own member function over the function in another class of which it is a friend?