他大概意思是:
struct foo{
friend void bar(foo* z){} //not static, its friend now
};
foo* z;
bar(z); //fine now
但隨後在技術上bar()
不內foo
。在foo
的封閉命名空間中仍然是仍然。
-
編輯:
他確實意味着friend
,爲he said(重點煤礦):
最好的例子是內部定義一個朋友功能類型
他的例子進一步說明。可能你需要閱讀「內部定義」,而不是「內部」。 「規定」
這個詞是所有使其中的差別,因爲它看起來像功能的名bar
引入類的範圍,但實際上,這個名字bar
引入封閉命名空間的foo
(見§3.3.1/ 3-4和§11.3/ 6)。
這裏是一個更好的例子:
namespace Demo
{
struct foo
{
friend void bar(foo* z){}
};
}
foo *z;
bar(z); //foo (type of z) is inside Demo, so is bar
//(even though bar is defined inside foo!)
bar(NULL); //error - NULL doesn't help ADL.
bar(nullptr); //error - nullptr doesn't help ADL.
bar(static<foo*>(NULL)); //ok - ADL
注意名稱bar
,即使引入命名空間Demo
,隱藏,從而不能使用平常的名字 - 外部使用查詢:
using namespace Demo; //brings ALL (visible) names from Demo to current scope
bar(NULL); //STILL error - means bar is invisible
或者,
Demo::bar(NULL); //error - not found
Demo::foo::bar(NULL); //error - not found
希望有幫助。
Bump ...發佈的答案沒有解決爲什麼ADL在此代碼中找不到「bar」的問題,它會轉而討論朋友函數 –