双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

谁能帮我解释一下为什么new后面有两个参数,开源代码中几个类定义,谢谢!

weakwater weakwater 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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后面有两个单数是啥意思?怎么解决?

以上代码如果不够我可以再贴,期待高手指点!
...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
weakwater
C++ 语言 65,214 成员 250,514 内容