c 11 – 获取decltype中使用的模板的基础类型
发布时间:2020-12-16 09:56:04 所属栏目:百科 来源:网络整理
导读:#include atomicstd::atomicint bar;auto foo() - decltype(bar){ return bar++;} 我收到此gcc错误消息: error: use of deleted function ‘std::atomicint::atomic(const std::atomicint)’ 将decltype()中的类型更改为int有效.为了使我的代码更加通用,我
#include <atomic> std::atomic<int> bar; auto foo() -> decltype(bar) { return bar++; } 我收到此gcc错误消息: error: use of deleted function ‘std::atomic<int>::atomic(const std::atomic<int>&)’ 将decltype()中的类型更改为int有效.为了使我的代码更加通用,我如何获得<>之间定义的int类型? 解决方法
你可以这样做:
auto foo() -> decltype(bar.operator++()) { return bar++; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |