Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:从长整型转换为非标量类型_gnu_cxx::_normal_迭代器 我试图在Linux中运行一个旧的C++代码(ReHAT)。我使用的是gcc版本4.1.2。 下面是我遇到错误的代码示例: template <class TP> TP *GCVVector<TP>::Find(const TP &Obj) { #ifdef WIN32 using namespace std; typedef typename vector<TP>::iterator Viterator; #else #ifdef __HP_aCC using namespace std; typedef typename vector<TP>::iterator Viterator; #else using namespace std; typedef typename std::vector<TP>::iterator Viterator; #endif #endif Viterator pCurrent =NULL ; template TP*GCVVector::Find(const TP&Obj) { #ifdef WIN32 使用名称空间std; typedef typename向量::迭代器Viterator; #否则 #ifdef\uuuuHP\uACC 使用名称空间std; typedef typename向量::迭代器Viterator; #否则 使用名称空间std; typedef typename std::vector::迭代器Viterator; #恩迪夫 #恩迪夫 Viterator pCurrent=NULL;_C++_Gcc_Cmake - Fatal编程技术网

错误:从长整型转换为非标量类型_gnu_cxx::_normal_迭代器 我试图在Linux中运行一个旧的C++代码(ReHAT)。我使用的是gcc版本4.1.2。 下面是我遇到错误的代码示例: template <class TP> TP *GCVVector<TP>::Find(const TP &Obj) { #ifdef WIN32 using namespace std; typedef typename vector<TP>::iterator Viterator; #else #ifdef __HP_aCC using namespace std; typedef typename vector<TP>::iterator Viterator; #else using namespace std; typedef typename std::vector<TP>::iterator Viterator; #endif #endif Viterator pCurrent =NULL ; template TP*GCVVector::Find(const TP&Obj) { #ifdef WIN32 使用名称空间std; typedef typename向量::迭代器Viterator; #否则 #ifdef\uuuuHP\uACC 使用名称空间std; typedef typename向量::迭代器Viterator; #否则 使用名称空间std; typedef typename std::vector::迭代器Viterator; #恩迪夫 #恩迪夫 Viterator pCurrent=NULL;

错误:从长整型转换为非标量类型_gnu_cxx::_normal_迭代器 我试图在Linux中运行一个旧的C++代码(ReHAT)。我使用的是gcc版本4.1.2。 下面是我遇到错误的代码示例: template <class TP> TP *GCVVector<TP>::Find(const TP &Obj) { #ifdef WIN32 using namespace std; typedef typename vector<TP>::iterator Viterator; #else #ifdef __HP_aCC using namespace std; typedef typename vector<TP>::iterator Viterator; #else using namespace std; typedef typename std::vector<TP>::iterator Viterator; #endif #endif Viterator pCurrent =NULL ; template TP*GCVVector::Find(const TP&Obj) { #ifdef WIN32 使用名称空间std; typedef typename向量::迭代器Viterator; #否则 #ifdef\uuuuHP\uACC 使用名称空间std; typedef typename向量::迭代器Viterator; #否则 使用名称空间std; typedef typename std::vector::迭代器Viterator; #恩迪夫 #恩迪夫 Viterator pCurrent=NULL;,c++,gcc,cmake,C++,Gcc,Cmake,我得到的错误是: /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVVector.h: In member function âTP* GCVVector<TP>::Find(const TP&) [with TP = GCVAsso<GCVString, GCVString>::KeyNode]â: /trnuser1/rmtrain/Develop

我得到的错误是:

         /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVVector.h: In member          function âTP* GCVVector<TP>::Find(const TP&) [with TP = GCVAsso<GCVString, GCVString>::KeyNode]â:
        /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVAsso.h:165:   instantiated from âbool GCVAsso<KTP, VTP>::Add(KTP, VTP) [with KTP = GCVString, VTP = GCVString]â
        /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.h:69:   instantiated from here
         /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVVector.h:398: error: conversion from âlong intâ to non-scalar type â__gnu_cxx::__normal_iterator<GCVAsso<GCVString, GCVString>::KeyNode*, std::vector<GCVAsso<GCVString, GCVString>::KeyNode, std::allocator<GCVAsso<GCVString, GCVString>::KeyNode> > >â requested
           /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVAsso.h:165:   instantiated from âbool GCVAsso<KTP, VTP>::Add(KTP, VTP) [with KTP = GCVString, VTP = GCVString]â
        /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.h:69:   instantiated from here
        /trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVVector.h:403: error: no match for âoperator=â in âpCurrent = GCVVector<TP>::BinarySearch [with TP = GCVAsso<GCVString, GCVString>::KeyNode](0l, (GCVVector<TP>::GetSize [with TP = GCVAsso<GCVString, GCVString>::KeyNode]() - 1l), ((const GCVAsso<GCVString, GCVString>::KeyNode&)((const GCVAsso<GCVString, GCVString>::KeyNode*)Obj)))â
        /usr/lib/gcc/x86_64-redhat-   linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_iterator.h:634: note: candidates are: __gnu_cxx::__normal_iterator<GCVAsso<GCVString, GCVString>::KeyNode*, std::vector<GCVAsso<GCVString, GCVString>::KeyNode, std::allocator<GCVAsso<GCVString, GCVString>::KeyNode> > >& __gnu_cxx::__normal_iterator<GCVAsso<GCVString,         GCVString>::KeyNode*, std::vector<GCVAsso<GCVString, GCVString>::KeyNode, std::allocator<GCVAsso<GCVString, GCVString>::KeyNode> > >::operator=(const __gnu_cxx::__normal_iterator<GCVAsso<GCVString, GCVString>::KeyNode*, std::vector<GCVAsso<GCVString, GCVString>::KeyNode, std::allocator<GCVAsso<GCVString, GCVString>::KeyNode> > >&)
        make[2]: ***    [CMakeFiles/GCVCore.dir/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.o] Error 1
        make[1]: *** [CMakeFiles/GCVCore.dir/all] Error 2
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVVector.h:在成员函数-TP*GCVVector::Find(const-TP&)[with-TP=GCVAsso::KeyNode]
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVAsso.h:165:实例化自–bool GCVAsso::Add(KTP,VTP)[with KTP=GCVString,VTP=GCVString]
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.h:69:从此处实例化
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVVector.h:398:错误:请求从“long int”转换为非标量类型
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVAsso.h:165:实例化自–bool GCVAsso::Add(KTP,VTP)[with KTP=GCVString,VTP=GCVString]
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.h:69:从此处实例化
/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVVector.h:403:错误:与-operator=in-pCurrent=GCVVector::BinarySearch[with-TP=GCVAsso::KeyNode](0l,(GCVVector::GetSize[with-TP=GCVAsso::KeyNode]()-1l),((const-GCVAsso::KeyNode&)((const-GCVAsso::KeyNode*))Obj))不匹配
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../../../../include/c++/4.1.2/bits/stl_iterator.h:634:注:候选项为:uu gnu_cxx:u normal_u迭代器和u gnu cxx::u normal iterator::operator=(const u gnu cxx:u normal
make[2]:***[CMakeFiles/GCVCore.dir/trnuser1/rmtrain/DevelopmentEnv/Generic/CoreObjects/GCVTransformationServices.o]错误1
生成[1]:***[CMakeFiles/GCVCore.dir/all]错误2

迭代器不是一个数字,它是一个在大多数情况下不将数字作为构造函数参数的对象

只要把线路换成

Viterator pCurrent = Viterator();

它将以与当前代码相同的方式出错。

原始代码是针对STL编写的,其中
std::vector::iterator
是原始指针,因此可以(并且需要)初始化为NULL

为了完全兼容,请将行更改为

Viterator pCurrent = Viterator();
在C++11中,可以使用

Viterator pCurrent{};
完全兼容意味着
Viterator
可能只是一个简单的指针。在这种情况下,显式将其设置为默认构造值将其设置为NULL。下面是一个简单的示例来演示它

#include <iostream>

typedef void * Iterator;

int main(int, char**)
{
  Iterator v1, v2=Iterator();
  std::cout << "uninitialized pointer: " << v1 << "\ninitialized pointer: " << v2 << std::endl;
}

请注意,如果程序使用
pccurrent
执行任何操作,而不是为其分配一个新值(将其与自身或通过复制初始化的另一个迭代器进行比较是有效的,但与非奇异迭代器进行比较,或者单独构造的默认值迭代器是未定义的),则程序可能仍然不正确.

@Kuba:如果迭代器类型确实是指针,则不会对其进行初始化,但不是在C++03中。Xeo:你说得对!!谢谢你这么说。坦白地说,我从来没有需要默认构造这样的简单类型,所以我从来没有想过要尝试。@Xeo:这表明这是一个令人难以置信的网站。我整个月都在学习。再次感谢,当有人指出一些事情时,我总是很感激我不知道。对我来说更强大;)
iterator()==iterator()
不保证。如果旧程序依赖空迭代器(而不是礼貌地避免未初始化的迭代器),可能仍然存在问题。@aschepler:好吧,原始代码已经在通过检查编译目标来解决编译器的缺陷,从而提出了问题……如果迭代器是指针或POD结构,这可能会使迭代器未初始化。@Xeo您说您需要一个
{}<代码> >正确地初始化它。在C++ 03中,即使是结构也不能满足代码< >(代码)>还是初始化保证在C++ 11中被首先引入?<代码>类型名称();< /C> >也被称为C++中,这实际上声明了一个函数。
uninitialized pointer: 0x7fff5fc01052
initialized pointer: 0