gpt4 book ai didi

c++ - 什么时候一种类型与另一种类型兼容?

转载 作者:太空宇宙 更新时间:2023-11-04 12:52:01 25 4
gpt4 key购买 nike

在 C++ 中,什么时候类型与另一种类型兼容?我查看了标准,但找不到类型兼容性的定义。

标准 (n3690) 中的使用示例:第 18.10 节运行时支持:

If the parameter parmN is of a reference type, or of a type that is not compatible with the type that results when passing an argument for which there is no parameter, the behavior is undefined.

如果类型可以相互隐式转换,它们是否简单地相互“兼容”?

最佳答案

C++ 没有“兼容类型”的概念,而 C 有。

在 C 中,同一实体的两个声明必须声明兼容的类型,而在 C++ 中,此约束由 [basic.link]/10 代替:

After all adjustments of types (during which typedefs are replaced by their definitions), the types specified by all declarations referring to a given variable or function shall be identical, except that declarations for an array object can specify array types that differ by the presence or absence of a major array bound ([dcl.array]). A violation of this rule on type identity does not require a diagnostic.

您引用的措辞是对 <cstdarg> 的描述header,来自对应的C header。所以你可以把这里的“compatible”看成是C中的同一个概念。

关于c++ - 什么时候一种类型与另一种类型兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48667188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com