代码片如下:
template<typename T>
struct secure_allocator :public std::allocator<T>
{
typedef std::allocator<T> base;
//size_type就是size_t,去平台化
//for ( std::vector<int>::size_type i = 0; i < a.size(); i++ )
//和for ( int i = 0; i < a.size(); i++ )后者可能报warning C4018: “<”: 有符号/无符号不匹配
typedef typename base::size_type size_type;
typedef typename base::difference_type difference_type;
typedef typename base::pointer pointer;
typedef typename base::const_pointer const_pointer;
typedef typename base::reference reference;
typedef typename base::const_reference const_reference;
typedef typename base::value_type value_type;
secure_allocator() throw() {} // 构造函数必须实现
secure_allocator(const secure_allocator& a) throw():base(a) {}
~secure_allocator() throw() {}
//rebind 实现对不同类型使用同一种内存分配策略的要求
//必须要重新定义,否则容器如 list, set, map 使用时作用域只能到达 std::allocator
template<typename _Other>
struct rebind
{
typedef secure_allocator<_Other> other;
};
void deallocate(T* p, std::size_t n)
{
if (p != NULL)
memset(p, 0, sizeof(T) * n);
allocator<T>::deallocate(p, n);
}
};
后面变量定义:
std::vector<char, secure_allocator<char>> vch;
编译提示:
错误 C2664 “secure_allocator<_Other>::secure_allocator(const secure_allocator<_Other> &) throw()”: 无法将参数 1 从“secure_allocator”转换为“const secure_allocator<_Other> &” C
使用VS2017: c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.12.25827\include\vector 554
请问如何修改啊?