【发布时间】:2018-10-11 23:13:18
【问题描述】:
我想将 const 添加到 typedef const A B; 的引用类型中。
不知何故,它不起作用。这在 c++ 中是不可能的吗?
测试:
#include <type_traits>
typedef int& A;
typedef const A B; // <-- Add const
// typedef std::add_const<A>::type B; // also doesn't work.
static_assert(std::is_const<typename std::remove_reference<
B>::type>::value, "is const");
int main() {
return 0;
}
编译错误:
add2.cpp:5:1: error: static assertion failed: is const
static_assert(std::is_const<typename std::remove_reference<
^~~~~~~~~~~~~
【问题讨论】: