C++ 获取迭代器错误的位置

C++ 获取迭代器错误的位置,c++,iterator,containers,distance,C++,Iterator,Containers,Distance,我有一些这样的代码 forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter) { PtrDictionary<phaseModel>& PtrDict = fluid.phases(); int IteratorPosition = std::distance(PtrDict.begin(), iter); } 不幸的是,在编译代码时,我得到了错误 error: no matching funct

我有一些这样的代码

forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter)
{

PtrDictionary<phaseModel>& PtrDict = fluid.phases();
int IteratorPosition = std::distance(PtrDict.begin(), iter);

}
不幸的是,在编译代码时,我得到了错误

error: no matching function for call to ‘distance(Foam::DLListBase::const_iterator, Foam::LPtrList<Foam::DLListBase, Foam::phaseModel>::iterator&)’
错误:调用“distance(Foam::DLListBase::const_iterator,Foam::LPtrList::iterator&)”时没有匹配的函数
我想问题在于迭代器是不同类型的?有人有办法解决这个问题吗

编辑:PtrDictionary类的代码:

namespace Foam
   48 {
   49 
   50 /*---------------------------------------------------------------------------*\
   51                         Class PtrDictionary Declaration
   52 \*---------------------------------------------------------------------------*/
   53 
   54 template<class T>
   55 class PtrDictionary
   56 :
   57     public DictionaryBase<DLPtrList<T>, T>
   58 {
   59 
   60 public:
   61 
   62     // Constructors
   63 
   64         //- Construct given initial table size
   65         PtrDictionary(const label size = 128);
   66 
   67         //- Copy construct
   68         PtrDictionary(const PtrDictionary&);
   69 
   70         //- Construct from Istream using given Istream constructor class
   71         template<class INew>
   72         PtrDictionary(Istream&, const INew&);
   73 
   74         //- Construct from Istream
   75         PtrDictionary(Istream&);
   76 };
   77 
   78 
   79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
   80 
   81 } // End namespace Foam
   82 
   83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
   84 
   85 #ifdef NoRepository
   86 #   include "PtrDictionary.C"
   87 #endif
   88 
   89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
   90 
   91 #endif
名称空间泡沫
48 {
49
50 /*---------------------------------------------------------------------------*\
51类词典声明
52 \*---------------------------------------------------------------------------*/
53
54模板
55类词典
56 :
57公共词典库
58 {
59
60公众:
61
62//构造函数
63
64/-给定初始表大小的构造
65 PtrDictionary(常量标签大小=128);
66
67//复制构造
68个词典(常量词典&);
69
70/-使用给定的Istream构造函数类从Istream构造
71模板
72词典(Istream和const INew和);
73
74/-从Istream构建
75部词典(Istream&);
76 };
77
78
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80
81}//结束命名空间泡沫
82
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84
85#如果没有保存
86#包括“PtrDictionary.C”
87#endif
88
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90
91#endif
编辑2:

方法begin():

模板
363内联类型名Foam::PtrList::迭代器Foam::PtrList::begin()
364 {
365返回ptrs_uu.begin();
366 }
迭代器构造函数(希望这是正确的):

迭代器(LListBase\u迭代器baseIter)
192             :
193 LList::迭代器(baseIter)
194             {}

问候streight

在没有模糊宏的情况下重新启动,似乎

PtrDictionary<phaseModel>::iterator
鉴于

fluid.phases().begin()
返回类型为的内容

Foam::LPtrList<Foam::DLListBase, Foam::phaseModel>::iterator&
Foam::LPtrList::迭代器&

因此,在某个地方,类型正在发生变化……从fluid.phases()分配容器时,或者从begin()返回迭代器时

我们可以从
PtrDictionary
类中添加一些代码吗?@Raxvan类代码。使用常规for循环而不是宏?@Graham Griffiths:当您查看宏
的定义时,对于Alliter
iter
应该是
PtrDictionary
类型。但是,当您查看错误消息时,似乎
iter
属于
Foam::LPtrList::iterator&
@Streight-cam类型,我们查看了
begin
函数和迭代器构造函数?我将检查一下:)我使用了另一种解决问题的方法,但我想你所指的方向也会带来一个解决方案,如果我正在使用的库被完整描述的话,我会尝试它
PtrDictionary<phaseModel>::iterator
Foam::DLListBase::const_iterator
fluid.phases().begin()
Foam::LPtrList<Foam::DLListBase, Foam::phaseModel>::iterator&