gpt4 book ai didi

c++ - typedef-name 作为基类 : illegal but widely tolerated

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:39:52 25 4
gpt4 key购买 nike

[class.derived]的第一段说的是基类说明符,

If the name found is not a class-name, the program is ill-formed.

但是,一个 simple测试表明 Comeau 和 g++ -ansi -pedantic 都接受 typedef-name 作为基础。 Boost header 上的简单 grep -r '[^:]: mpl' 表明流行的库通常依赖于这种行为。

是否有任何编译器实际上拒绝了基说明符中类的 typedef? GCC 甚至检查基类类型是否不是 const,这改进了非标准功能。

有解决办法吗?我唯一能想到的就是用 C++11 别名模板替换 typedef。一个模板化的别名声明声明了一个模板名,它可能会变成一个类名……我想。这可能需要别名声明的虚拟参数。

也许应该调整标准以匹配编译器的一致行为。有 DR 吗?

最佳答案

我相信这是符合标准的。具体来说,§9.1/5:“命名类的 typedef-name (7.1.3) 是 class-name,[...]”。

关于c++ - typedef-name 作为基类 : illegal but widely tolerated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5813499/

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