谁能帮我解释一下为什么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后面有两个单数是啥意思?怎么解决?
以上代码如果不够我可以再贴,期待高手指点!
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后面有两个单数是啥意思?怎么解决?
以上代码如果不够我可以再贴,期待高手指点!
...全文
相关推荐
java 获取冒号后面的参数(正则)实现代码
主要介绍了java 获取冒号后面的参数(正则)实现代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
New API:专为AI服务设计的开源API网关部署与实战指南
API网关是现代微服务架构中的核心组件,负责请求路由、认证、限流、监控等关键功能,是保障系统稳定性和安全性的重要基础设施。其工作原理是通过在客户端与后端服务之间建立一个统一的入口,对流量进行集中管控和治理。在AI应用快速发展的背景下,传统API网关在管理大语言模型、图像生成等AI服务时面临诸多挑战,例如难以处理长耗时请求、流式响应,以及缺乏对Token计费、Prompt日志等AI特有场景的原生支持。New API作为一个开源API网关项目,正是为解决这些问题而生。它通过模块化、插件化的架构,重新设计了路由、
OpenSource-Cooking:一个开源的 Dreambot 烹饪脚本!
开源烹饪 一个开源的 Dreambot 烹饪脚本!
qtwinmigrate-2.8-opensource
qtwinmigrate-2.8-opensource
OpenSource-Fishing:一个开源的 Dreambot 钓鱼脚本!
开源-钓鱼 一个开源的 Dreambot 钓鱼脚本!



