谁能帮我解释一下为什么new后面有两个参数,开源代码中几个类定义,谢谢!
webkit中的几个类定义:
template<bool isInteger, typename T> struct GenericHashTraitsBase;
template<typename T> struct GenericHashTraitsBase<false, T> {
static const bool emptyValueIsZero = false;
static const bool needsDestruction = true;
};
// Default integer traits disallow both 0 and -1 as keys (max value instead of -1 for unsigned).
template<typename T> struct GenericHashTraitsBase<true, T> {
static const bool emptyValueIsZero = true;
static const bool needsDestruction = false;
static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1); }
static bool isDeletedValue(T value) { return value == static_cast<T>(-1); }
};
template<typename T> struct GenericHashTraits : GenericHashTraitsBase<IsInteger<T>::value, T> {
typedef T TraitType;
static T emptyValue() { return T(); }
};
struct FormElementKeyHashTraits : WTF::GenericHashTraits<FormElementKey> {
static void constructDeletedValue(FormElementKey& slot) { new (&slot) FormElementKey(WTF::HashTableDeletedValue); }
static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); }
};
可以看出 FormElementKeyHashTraits 继承自GenericHashTraits 又继承自GenericHashTraitsBase
GenericHashTraitsBase有两个定义分别对应第一个参数是true和false
问题就是那段橙色代码中的new (&slot) FormElementKey(WTF::HashTableDeletedValue); 出错了:
error C2661: “operator new”: 没有重载函数接受 2 个参数
其中WTF::HashTableDeletedValue是一个枚举变量值,值为0
请问,这个new后面有两个单数是啥意思?怎么解决?
以上代码如果不够我可以再贴,期待高手指点!