作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个常量声明如下:
const auto val = someFun();
现在我想要另一个具有相同类型“val”但没有常量规范的变量。
decltype(val) nonConstVal = someOtherFun();
// Modify nonConstVal, this is error when using decltype
目前 decltype 保持常量。如何剥离?
最佳答案
来自 <type_traits>
你可以在 C++14 中使用:
std::remove_cv_t<decltype(val)> nonConstVal = someOtherFun();
或者在 C++11 中
std::remove_cv<decltype(val)>::type nonConstVal = someOtherFun();
关于c++ - 使用 declytype 推导类型时删除 CV 限定符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32307342/
我有一个常量声明如下: const auto val = someFun(); 现在我想要另一个具有相同类型“val”但没有常量规范的变量。 decltype(val) nonConstVal = s
我是一名优秀的程序员,十分优秀!