加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何将函数(std :: bind)包装到命名空间中?

发布时间:2020-12-16 10:26:18 所属栏目:百科 来源:网络整理
导读:我想将绑定类模板包装到一个单独的命名空间: namespace my_space {templatetypename... R using bind = std::bindR...;} 并得到一个错误: error: 'bindR ...' in namespace 'std' does not name a type. 我怎么能这样做?一个小例子可以找到here. 解决方法
我想将绑定类模板包装到一个单独的命名空间:

namespace my_space {
template<typename... R> using bind = std::bind<R...>;
}

并得到一个错误:

error: 'bind<R ...>' in namespace 'std' does not name a type.

我怎么能这样做?一个小例子可以找到here.

解决方法

为什么你的代码不起作用

您的代码无法编译,因为std :: bind是一个函数,而不是一个类型.您可以仅使用类型来声明别名.

虽然g诊断并不是最好的,但Clang会出现以下错误:

error: expected a type

哪个更清楚*.

你可以做什么

谢天谢地,您可以使用以下命令导入std :: bind名称:

namespace my_space {
    using std::bind;
}

Live demo

具体定义如下:

§7.3.3/1 The using declaration [namespace.alias]

A using-declaration introduces a name into the declarative region in which the using-declaration appears.

* 个人意见.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读