gpt4 book ai didi

templates - 使用声明引用到 C,它是 D 的基类(别名),但它不被识别为有效

转载 作者:行者123 更新时间:2023-12-01 06:06:51 25 4
gpt4 key购买 nike

这看起来像是 clang 中的一个问题(我已经打开了 bug to clang ),但我想确保我没有做错。

考虑以下代码:

struct B { };

template<typename...>
struct D;

template<typename T, typename U, typename... A>
struct D<T, U, A...>: D<U, A...> {
using C = D<U, A...>; // (1)
// using D<U, A...>::D; // (2)
// using C::C; // (3)
using C::D; // (4)
};

template<typename T>
struct D<T>: T { using T::T; };

int main() {
D<int, double, B> d{};
}

第 (2) 行(如果注释掉 (1) 和 (4))和 (3)(如果注释掉 (4))按预期工作,而 (1)(上面的示例)给出了以下错误:

11 : error: dependent using declaration resolved to type without 'typename'
using C::D;

[...]

11 : error: using declaration refers into 'C::', which is not a base class of 'D'
using C::D;



不管怎样, CD<U, A...> 的别名,这是 D<T, U, A...> 的基类.
据我所知,该片段应该可以编译。我错了吗?

请注意,GCC 至少从 v4.8.1 开始编译它。至 v6.1 .

最佳答案

正如在 clang 的票中提到的,它不能被认为是一个错误(也许):

Clang is following the direction of core issue 2070 (http://wg21.link/cwg2070), which matches the intent of the original proposal (see the end of "Outline of the Solution" in http://wg21.link/n2540). As such, this is working as intended. To inherit a constructor, you need to use the same identifier before and after the ::.

关于templates - 使用声明引用到 C,它是 D 的基类(别名),但它不被识别为有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37564776/

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