我正在使用 g++ 4.4.7 进行编译(目前无法升级),并使用 -std=gnu++0x
编译器开关,该开关应允许第三行的语法。
typedef std::vector<CI_RecordInfo_Pair> CI_RecordInfo_Vector;
typedef std::vector<std::pair<std::string, CI_RecordInfo_Vector*> > MgrBlks;
MgrBlks mgr_n_blks { {"T2M_NAME", NULL} }; // <--- line 59
然而,编译器报错如下:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h: In constructor 'std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = const char (&)[9], _U2 = long int, _T1 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _T2 = CI_RecordInfo_Vector*]':
tom.cpp:59: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:90: error: invalid conversion from 'long int' to 'CI_RecordInfo_Vector*'
我假设 "long int" 是 NULL,并且由于某些原因我无法将其转换为指针。不过在结构体的映射中,我能够编译出类似以下的内容。
foo["X"] = { NULL, "bar", 12 }; // first element is a pointer
有什么不同之处?
nullptr
代替NULL
可以吗? - Eric Finn