有没有办法解决这个模板循环依赖关系
Is there a way to resolve this template circular dependency
是否有通用方法来解决模板中的这种类型的循环依赖关系,还是无法正常工作?
#include <tuple>
template<class... T>
struct A {
std::tuple<T...> t;
};
template<class type_of_A>
struct D1 {
type_of_A* p;
};
template<class type_of_A>
struct D2 {
type_of_A* p;
};
using A_type = A<D1<???>, D2<???>>; // <------
int main() { }
像往常一样,在混合中插入一个命名的间接寻址以打破无限递归:
template<class... T>
struct A {
std::tuple<T...> t;
};
template<class type_of_A>
struct D1 {
typename type_of_A::type* p; // Indirection
};
template<class type_of_A>
struct D2 {
typename type_of_A::type* p; // Indirection
};
// Type factory while we're at it
template <template <class> class... Ds>
struct MakeA {
using type = A<Ds<MakeA>...>; // Hey, that's me!
};
using A_type = typename MakeA<D1, D2>::type;
MakeA
注入的类名的行为是一个奖励,但我们可以将其拼写为 MakeA<Ds...>
.
在科里鲁现场观看
相关文章:
- C++GTKMM gui循环依赖关系
- 如何在头文件中声明类模板(由于循环依赖关系)
- 如何在具有循环依赖的类中dynamic_cast?
- C++模板方法中的循环依赖关系
- 修复循环依赖项 c++17 标头
- 涉及全局对象的循环依赖C++
- 循环依赖,在继承类的情况下使用覆盖方法
- Wt::D bo 中的循环依赖关系
- 在包含窗口标头时难以解决循环依赖关系问题
- 解决循环依赖关系 c++ 的想法
- C++循环依赖关系,未声明的标识符
- C++ 中的循环依赖关系问题
- 错误 C2512 视觉C++(并且不是循环依赖项)
- CMake 外部和内部静态库的循环依赖关系
- 正在从继承中解析循环依赖项
- "std::shared_ptr"循环依赖关系是如何导致问题的
- 纯引用而不是weak_ptr来打破循环依赖关系
- "invalid use of incomplete type" .解决循环依赖关系
- 如何避免模板方法的循环依赖
- 循环依赖结构,使用前向声明时结构的错误重定义