相关疑难解决方法(0)

内联朋友功能的范围是什么?

在搜索到SO之后,一个问题告诉我,内联友元函数的词法范围是它定义的类,这意味着它可以访问例如typedef类中的s而不限定它们.但后来我想知道这种功能的实际范围是什么?海湾合作委员会至少拒绝我所有打电话的尝试.可以通过除ADL以外的方式调用示例中的函数,由于没有参数,这是不可能的吗?

标准报价表示赞赏,因为我目前无法访问我的副本.

以下代码

namespace foo{
  struct bar{
    friend void baz(){}
    void call_friend();
  };
}

int main(){
  foo::baz();           // can't access through enclosing scope of the class
  foo::bar::baz();    // can't access through class scope
}

namespace foo{
  void bar::call_friend(){
    baz();    // can't access through member function
  }
}
Run Code Online (Sandbox Code Playgroud)

导致这些错误:

prog.cpp: In function ‘int main()’:
prog.cpp:9: error: ‘baz’ is not a member of ‘foo’
prog.cpp:10: error: ‘baz’ is not a member of ‘foo::bar’
prog.cpp: In member …
Run Code Online (Sandbox Code Playgroud)

c++ scope inline friend

32
推荐指数
2
解决办法
5911
查看次数

标签 统计

c++ ×1

friend ×1

inline ×1

scope ×1