【问题标题】:If you introduce a friend within a class in the global namespace, the friend is injected globally如果你在全局命名空间的一个类中引入一个朋友,这个朋友会被全局注入
【发布时间】:2014-10-31 11:07:40
【问题描述】:

你可以通过在一个封闭的类中声明一个友元声明到一个命名空间中:

namespace Me {
class Us {
friend void you();
};
}

现在函数 you( ) 是命名空间 Me 的成员。 如果你在全局命名空间的一个类中介绍一个朋友, 朋友被全局注入。

谁能举例说明以上几行的含义。

【问题讨论】:

  • 你应该解释什么是你不明白的。

标签: c++ namespaces friend-function


【解决方案1】:

你可以通过在一个封闭的类中声明一个友元声明到一个命名空间中:

namespace Me {
class Us {
friend void you();
};
}

现在函数 you( ) 是命名空间 Me 的成员。 如果你在全局命名空间的一个类中介绍一个朋友, 朋友被全局注入。

【讨论】:

    猜你喜欢
    • 2011-01-15
    • 2011-01-13
    • 2021-02-23
    • 2011-10-12
    • 2018-10-20
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-03-07
    相关资源
    最近更新 更多