本文介绍了定义这两个类typedef map<C, B::iterator>一种 ;typedef list<D, A::iterator>乙“?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
定义这两个类
typedef map<C, B::iterator> A;
typedef list<D, A::iterator> B;
A 类和 B 类相互包含彼此的迭代器.编译器抱怨上述语句.如何解决问题?
The class A and B mutual contain each other's iterator.The compiler complains about above statement.How to solve the problem ?
iammilind 说这是不可能的.但是这个逻辑关系就出现了,比如一个优先级队列.那么有人有解决方法吗?
iammilind says it is impossible. but this logic relationship appears, for example a priority queue. So any one have workaround?
推荐答案
很遗憾,不可能.A
和 B
是相互依赖的,因此必须至少向前声明其中一个以支持另一个.
但是typedef
类型不能被前向声明为class/struct
.
Unfortunately, it's not possible.A
and B
are interdependent, so at least one of them has to be forward declared to support the other.
But the typedef
types cannot be forward declared as class/struct
.
这篇关于定义这两个类typedef map<C, B::iterator>一种 ;typedef list<D, A::iterator>乙“?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!