Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 重载运算符new函数中的限制_C++ - Fatal编程技术网

C++ 重载运算符new函数中的限制

C++ 重载运算符new函数中的限制,c++,C++,运算符new函数可以重载,但它要求第一个参数为无符号int,即重载函数也应将无符号int作为其第一个参数 // Okay since the first argument is unsigned int void * operator new(size_t size, Arena& arena, std::string msg) // Not okay. since the first argument is not an unsigned int void * operator new

运算符new函数可以重载,但它要求第一个参数为无符号int,即重载函数也应将无符号int作为其第一个参数

// Okay since the first argument is unsigned int
void * operator new(size_t size, Arena& arena, std::string msg)
// Not okay. since the first argument is not an unsigned int
void * operator new(Arena& arena, std::string msg)

这是如何执行的?在C++中,用户定义函数是否可以使用类似的约束?

< P>,在C++中,操作符签名是由C++标准确定的。该标准更进一步,并提到了一些不允许超载的运营商(
?:
等)

我不是一个语言的律师,它从C++标准中提取出一些东西,但在前面描述的是,对于任何一个操作符,都有被接受的预定义函数签名,用于<代码>新操作符< /代码>。使用示例中显示的函数签名,似乎定义了用户定义的放置分配函数。根据第一个参数,对于该特定运算符,新重载应始终为
size\t
类型


另外,它是
操作员新功能
而不是
操作员新功能

它被定义为一个功能。选中@SureshKumar,我们需要编写一个函数来重载运算符-这是正确的。我的意见是,我们称它为
opearator新函数
,与称它为
运算符重载
而不是
运算符函数重载
的方式不同。这只是这个词的用法,仅此而已。