Hi All,

in below class i wanted to have two friend function(overloading) one with default argument and other is without default argument.
but during compilation it gives error. could you let me know how to fix (overload) this by not changing the function name , argument type or number of arguments.

error:

warning: void fun(int, int, int) is already a friend of class foo

#include<iostream>
using namespace std;


class foo
{

public:
friend void fun (int a, int b, int c);
friend void fun (int a, int b, int c=20);

};

int main()
{

return 1;
}

Lines 9 and 10 essentially have the same function signatures, which is why you are getting this error. You need to remove line 9 which is friend void fun (int a, int b, int c);. In line 10, the default value for c should be OK. If not for your use, you need to explain your usage further.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.