如何在模板中添加常量限定符
How to add const qualifiers in template
即使T
是一个指针,我也想const_value_type
const std::add_const<>
所以我尝试了这样的事情:
template<typename value_type, bool is_pointer>
struct add_const_pointer{
typedef const value_type type;
};
template<typename value_type>
struct add_const_pointer<value_type, true>{
typedef const value_type *type;
};
template<typename T>
class Foo
{
public:
typedef T value_type;
typedef add_const_pointer<std::remove_pointer<T>, std::is_pointer<T>::value>::type const_value_type;
// here I get compiler error: missing type specifier - int assumed.
}
但我收到编译器错误:缺少类型说明符 - 假设为 int。
clang
错误消息会有所帮助
typedef typename add_const_pointer<
// ~~~~~~~~ Add typename
std::remove_pointer<T>,
std::is_pointer<T>::value>::type
const_value_type;
相关文章:
- 将常量字符串添加到非常量字符串是否会给出常量字符串
- interpret_cast添加常量
- 减去常量或将常量添加到大数组中
- 将上一行添加到 char* 数组中的 char* 常量
- 将常量添加到函数模板指针参数
- 将常量添加到引用
- 强制实施调用函数应向被调用函数返回的值添加常量的规则
- 如何将常量限定符添加到 vector<>::p ointer?
- 我应该在源文件之间共享的常量的定义中添加关键字"extern"吗
- 在多项式类中重载 += 运算符,用于添加多项式和常量
- C++static_cast添加常量和"this"对象的const_cast有什么区别?
- 恒常性添加无效?错误:无法使用字符**初始化常量字符**
- 如何将常量传递给我的动态数组类添加方法
- C++:是否有点将常量添加到作为参数传递的 POD 中
- 如何在模板中添加常量限定符
- 向成员函数添加常量限定符
- 是为添加常量而重新创建的对象/引用/指针
- C++ : 在左侧常量赋值上添加引用/别名 (&) 是多余的吗?
- 在 C++ 中将字符数组添加到常量字符数组的正确方法是什么?
- c++中没有匹配的函数:给调用函数添加常量标签