保留的函数名称可以重载吗? [英] Can reserved function names be overloaded?

查看:86
本文介绍了保留的函数名称可以重载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是此问题的后续问题.

请考虑以下程序:

#include <cmath>

// meaningless, only for language-lawyer purpose
void abs(void*) {}

int main(){
    abs(nullptr);
}

此程序会导致不确定的行为吗?

Does this program result in undefined behavior?

标准中的相关部分为 [extern.names]/4 :

使用外部链接声明的C标准库中的每个函数签名均保留给实现,以用作具有extern"C"和extern"C ++"链接的函数签名,或用作全局名称空间.

我不确定是否允许重载.

I'm not sure whether overloading is permitted.

推荐答案

该语句有两部分,因为它涉及(用于C ++实现的)保留名称(来自C标准).特别是

There are two parts to this statement, as it talks about names (from the C standard) that are reserved (for C++ implementations). In particular,

第1部分:声明的C标准库中的每个函数签名 有外部联系

Part 1: Each function signature from the C standard library declared with external linkage

这包括C库函数abs

第2部分:保留给实现以用作功能 带有外部"C"和外部"C ++"链接的签名,或作为名称 全局命名空间中的命名空间范围.

Part 2: is reserved to the implementation for use as a function signature with both extern "C" and extern "C++" linkage, or as a name of namespace scope in the global namespace.

因此,名称::abs为C ++实现保留.您不能使用它.过载是无关紧要的.

So the name ::abs is reserved for the C++ implementation. You can't use it. Overloading is irrelevant.

这篇关于保留的函数名称可以重载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆