正在解析循环依赖的嵌套类型说明符

Resolving circularly dependant nested type specifiers

本文关键字:嵌套类型 说明符 依赖 循环      更新时间:2023-10-16

很简单,有没有办法让A指代B::value_type,B指代A::value_type?

struct B;
struct A {
    using value_type = int;
    value_type a;
    B::value_type b;
};
struct B {
    using value_type = int;
    value_type b;
    A::value_type a;
};

只是以一种非常粗糙的方式。

template<int> struct Z
{
    struct B;
    struct A {
        using value_type = int;
        value_type a;
        typename B::value_type b;
    };
    struct B {
        using value_type = int;
        value_type b;
        typename A::value_type a;
    };
};
using A = Z<0>::A;
using B = Z<0>::B;