Talk:cpp/language/friend

I see you have operators, an example of conversions may be helpful too? From discussion @ stackoverflow http://stackoverflow.com/questions/41141119/c-friend-conversion-function

86.140.194.68 01:28, 15 December 2016 (PST)Michael Collier
 * following up on Talk:cpp/language/cast_operator --Cubbi (talk) 06:35, 15 December 2016 (PST)

friend function-definition	(2)	not accurate
The description of the second case is not accurate. For example, this code does not compile:

For an explanation, see https://stackoverflow.com/a/5695855.

78.45.209.17 12:21, 30 August 2019 (PDT)
 * this is already noted on this page, last paragraph under Notes (and in more detail on the page that links to) --Cubbi (talk) 13:56, 30 August 2019 (PDT)
 * I'd say this note is not sufficient. The current wording in (2): "Defines a non-member function, and makes it a friend of this class at the same time. Such non-member function is always inline." is certainly a very poor description of the actual behaviour, notes should be used to extend the primary description and not to fundamentally change its meaning. -- 78.45.209.17 14:16, 30 August 2019 (PDT)
 * The wording is correct as far as I see. What part of it do you believe is changed by the note about lookup rules? --Cubbi (talk) 14:28, 30 August 2019 (PDT)
 * It gives the impression that this code:


 * is equivalent to this code:


 * which it clearly isn't. -- 78.45.209.17 23:29, 30 August 2019 (PDT)
 * The item non-member function is clear enough in my opinion. --Fruderica (talk) 16:52, 15 September 2019 (PDT)
 * It is not clear enough because it does not say where the non-member function is defined, nor that it may not be visible for lookup. -- 78.45.209.17 06:20, 21 September 2019 (PDT)
 * Such description is in cpp/language/friend. And the latter form you mentioned definitely defines a member function which is never a non-member function. --Fruderica (talk) 09:10, 21 September 2019 (PDT)

Error in Template friends example?
This

does not compile for me (GCC 10.2.1)

I get the error: member 'int* A::h' declared as friend before type 'A' defined

172.70.250.116 13:59, 2 April 2023 (PDT)


 * The example actually comes from the standard, so it's most likely a compiler bug --Ybab321 (talk) 16:29, 2 April 2023 (PDT)


 * BTW, the example runs with e.g. "clang++ -std=c++98 -Wall -Wextra -Wpedantic ..." with warnings:

warning: dependent nested name specifier 'A::' for friend class declaration is not supported; turning off access control for 'X' [-Wunsupported-friend]
 * C++98 is irrelevant here, it compiles with C++ 03, 11, ... 23...
 * Adding the flag "-Wno-unsupported-friend" suppresses the warning.--Space Mission (talk) 03:42, 3 April 2023 (PDT)