May 30, 2012 at 8:46am UTC
class test{
public:
struct one{
};
friend one foo();
};
In vc2010, the compiler says foo() cannot overload functions distinguished by return type alone
Can anyone tell me what's wrong?
May 30, 2012 at 8:58am UTC
First of all you showed correct code. So the error has nothing common with your showed code. Next time show the ful code that produces the error.
As for the error itself it means that you have one more declaration of function foo which differs from the shown declaration only in return type.
May 30, 2012 at 11:09am UTC
This is THE code that vc2010 reports error, no more no less.
And there is no function other than foo(). So tell me what's wrong
May 30, 2012 at 11:11am UTC
Where is foo defined? Does the return type match the friend declaration?
May 30, 2012 at 11:19am UTC
No definition for foo(). Even if you give one, vc2010 still report error
May 30, 2012 at 11:22am UTC
If foo() isn't defined, why do you have a friend declaration?
May 30, 2012 at 11:23am UTC
It compiles without warning using GCC.
May 30, 2012 at 11:25am UTC
Same here, it compiles, I'm using vc2010
Last edited on May 30, 2012 at 11:25am UTC
May 30, 2012 at 12:01pm UTC
You don't have to have a definition. friend just informs the compiler that if foo() was a function that returned a one object, it's allowed to access test 's private members; a heads up, if you will.
Wazzak
Last edited on May 30, 2012 at 12:03pm UTC