List类的问题



  • 因为需要用到一些只能在com跑的工具箱,所以笔者打算将之前写的代码从Org版本迁移到com版本,但是发现自己掉坑里了。具体报错如下:

    In file included from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/List.H:322:0,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/HashTable.C:30,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/Istream.H:184,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/ISstream.H:39,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/IOstreams.H:38,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/VectorSpace.C:27,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/VectorSpace.H:233,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/Vector.H:44,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/vector.H:39,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/point.H:35,
                     from lnInclude/mooringLine.H:39,
                     from lnInclude/ICC.H:39,
                     from QCC/QCC.H:39,
                     from QCC/QCC.C:26:
    /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/List.C: In instantiation of ‘Foam::List<T>::List(InputIterator, InputIterator) [with InputIterator = int; T = double]’:
    QCC/QCC.C:230:40:   required from here
    /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/List.C:213:44: error: no matching function for call to ‘distance(int&, int&)’
         List<T>(begIter, endIter, std::distance(begIter, endIter))
                                                ^
    In file included from /usr/include/c++/5/bits/stl_algobase.h:66:0,
                     from /usr/include/c++/5/bits/char_traits.h:39,
                     from /usr/include/c++/5/string:40,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/string.H:51,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/word.H:43,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/int32.H:43,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/int.H:38,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/label.H:39,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/doubleFloat.H:29,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/floatScalar.H:38,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/scalar.H:39,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/vector.H:38,
                     from /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/point.H:35,
                     from lnInclude/mooringLine.H:39,
                     from lnInclude/ICC.H:39,
                     from QCC/QCC.H:39,
                     from QCC/QCC.C:26:
    /usr/include/c++/5/bits/stl_iterator_base_funcs.h:114:5: note: candidate: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator)
         distance(_InputIterator __first, _InputIterator __last)
         ^
    /usr/include/c++/5/bits/stl_iterator_base_funcs.h:114:5: note:   template argument deduction/substitution failed:
    /usr/include/c++/5/bits/stl_iterator_base_funcs.h: In substitution of ‘template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) [with _InputIterator = int]’:
    /home/cybrex/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude/List.C:213:44:   required from ‘Foam::List<T>::List(InputIterator, InputIterator) [with InputIterator = int; T = double]’
    QCC/QCC.C:230:40:   required from here
    /usr/include/c++/5/bits/stl_iterator_base_funcs.h:114:5: error: no type named ‘difference_type’ in ‘struct std::iterator_traits<int>’
    

    通过代码可以定位到类的一个成员函数,这里我声明了2个ScalarList与2个VectorList,然后会出现这个错误。
    但是这个类的变量里面是有其他ScalarList以及VectorList的,所以个人觉得坑应该是在成员函数声明List 类的问题上,
    但是又不太清楚这么底层的东西该如何修改,望各位赐教!谢谢!



  • 忘记提了,自己之前是4.x环境,这么写是完全没问题的,但是实测v1712跟v1812都会有报这个错:zoule:



  • @秋山结月List类的问题 中说:

    但是又不太清楚这么底层的东西该如何修改,望各位赐教!谢谢!

    这种底层的变动太大了,底层变一点,上层整栋楼都变了,不建议这么做,要么直接用com吧,要么把org顶层的弄到com,不要动底层



  • @秋山结月List类的问题 中说:

    distance

    OF4 的代码,就算更新到更新的 org 版本也会报这个错。
    问题一般出现在 List 的初始化上,比如
    scalarList y(2, 0) 需要改成 scalarList y(2, 0.)
    List<label> a(2, 1) 需要改成 List<label> a(2, label(1))



  • @浪迹天大 谢谢您! 问题解决了


Log in to reply
 

CFD中文网 2016 - 2020 | 京ICP备15017992号-2