Mar 8, 2020 at 2:28pm UTC
Which of two functions of one name will be called, the one declared in a class of the object invoking it or one in a class within which a friend to the first class is stated?
Last edited on Mar 8, 2020 at 2:29pm UTC
Mar 8, 2020 at 2:35pm UTC
Why not try it out yourself?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
// Example program
#include <iostream>
void func()
{
std::cout << "func [outside class]\n" ;
}
class Floob {
friend void func();
public :
void floo()
{
func();
}
void func()
{
std::cout << "func [inside class]\n" ;
}
private :
int a;
};
int main()
{
Floob floob;
floob.floo();
}
If you want to access the friend function, you can do:
1 2 3 4
void floo()
{
::func();
}
Last edited on Mar 8, 2020 at 2:41pm UTC