what's wrong with this piece of code


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?
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.
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
Where is foo defined? Does the return type match the friend declaration?
No definition for foo(). Even if you give one, vc2010 still report error
If foo() isn't defined, why do you have a friend declaration?
It compiles without warning using GCC.
Same here, it compiles, I'm using vc2010
Last edited on
closed account (zb0S216C)
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
Topic archived. No new replies allowed.