圆形类型定义
Circular Typedefs
此代码编译失败:
class B;
class A{
typedef int AThing;
typedef B::BThing BThing;
};
class B{
typedef int BThing;
typedef A::Athing AThing;
};
因为A
需要B
的typedef
,而B
需要A
的。
使用具有循环依赖项的 typedef 的典型方法是什么?
具有此类循环typedef
依赖项的典型解决方案是不要具有此类循环typedef
依赖项。这些类型的循环typedef
依赖关系无法在C++中完成,因此您必须重新排列类层次结构:
class B;
typedef int this_is_a_BThing;
class A{
typedef int AThing;
typedef this_is_a_Bthing BThing;
};
class B{
typedef this_is_a_BThing BThing;
typedef A::Athing AThing;
};
使用具有循环依赖项的 typedef 的典型方法是什么?
没有这种典型的方法,你不能那样做。
有关如何使用前向声明并在类型范围内扩展依赖类型定义的情况,请参阅 Resolve 标头中的答案包括C++中的循环依赖项。
您在类范围内引入typedef
的情况与编译器无法通过查看前向声明来解决它这一事实无关紧要。
我能想到使用 typedefs 的唯一方法是使用 Pimpl Idion 并仅在实现中实际引入它们。
相关文章:
- 使用QJsEngine在Qt中注册自定义类型
- 在UE4中使用未定义类型'UTextBlock'
- 修改"std::set"中用户定义类型的值
- 当我使用自定义类型创建动态数组时,即使使用字符串,它似乎也不起作用
- QtQuick - qml:28:错误:未知方法返回类型:自定义类型
- 如何使自定义类型在unordered_map中用作键
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- Qt5 远程对象 + 自定义类型,但不在 POD 中
- 为什么转换函数声明不需要至少一个定义类型说明符
- 标准::原子中的自定义类型
- 如何使用自定义类型声明Arduino数组?
- 如何在 Cython 中定义返回 cpp 定义类型的函数?
- 使用自定义访问者时具有自定义类型的提升变体失败(源自 boost::static_visitor)
- 您可以将binary_search应用于具有自定义类型的矢量吗?
- 在自定义类型图中重用 SWIG 映射
- 扩展自定义类型的spdlog
- vim使用户定义类型的COLOR与C++中的基本类型相同
- 重载自定义类型的 std::to_string 和 std::to_chars?
- 具有未声明/未定义类型的 typedef 结构
- 函数重载:内置类型与用户定义类型