I have a constant declared as following:
const auto val = someFun();
Now I want another variable with same type of 'val' but without the constant specification.
decltype(val) nonConstVal = someOtherFun();
// Modify nonConstVal, this is error when using decltype
Currently decltype keeps the constness. How to strip it?
From <type_traits>
You may use in C++14:
std::remove_cv_t<decltype(val)> nonConstVal = someOtherFun();
or in C++11
std::remove_cv<decltype(val)>::type nonConstVal = someOtherFun();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.