A question about friend functions
Posted
by
Als
on Stack Overflow
See other posts from Stack Overflow
or by Als
Published on 2011-02-21T15:21:38Z
Indexed on
2011/02/21
15:25 UTC
Read the original article
Hit count: 291
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?
© Stack Overflow or respective owner