【发布时间】:2016-06-03 21:39:22
【问题描述】:
我已经在 Stack Overflow 上的其他主题中看到了这个问题的答案,但我不确定在我的情况下该怎么做。我是模板的新手,这是我/曾经/使用从该网站找到的示例创建的第一个模板。无论如何,这是下面的代码和相关的错误:
warning: base class 'class std::allocator<char>' should be explicitly initialized in the copy constructor [-Wextra]
SecureString(const SecureString &) throw() {}
template<class T> class SecureString : public std::allocator<T> {
public:
template<class U> struct rebind { typedef SecureString<U> other; };
SecureString() throw() {}
SecureString(const SecureString &) throw() {}
template <class U> SecureString(const SecureString<U>&) throw() {}
void deallocate(T *p, size_t n) {
#ifdef _WIN32
SecureZeroMemory((void *)p, n);
#elif __linux__
std::fill_n((volatile char *)p, (n * sizeof(T)), 0);
#endif
std::allocator<T>::deallocate(p, n);
}
};
还有更多错误,但这是主要错误。我从示例中学到了最好的东西,所以任何帮助都将不胜感激,谢谢。
【问题讨论】:
标签: c++ templates c++11 allocation stdstring