1

我正在尝试声明矢量地图,但它给出了错误。

我的代码:

int main() {

    map <int, vector<int> > ele;

return 0;
}

错误 :

In function `__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<int const, std::vector<int, std::allocator<int> > > > >::deallocate(std::_Rb_tree_node<std::pair<int const, std::vector<int, std::allocator<int> > > >*, unsigned int)':
q2.cpp:(.text._ZN9__gnu_cxx13new_allocatorISt13_Rb_tree_nodeISt4pairIKiSt6vectorIiSaIiEEEEE10deallocateEPS8_j[__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<int const, std::vector<int, std::allocator<int> > > > >::deallocate(std::_Rb_tree_node<std::pair<int const, std::vector<int, std::allocator<int> > > >*, unsigned int)]+0xd): undefined reference to `operator delete(void*)'
/tmp/ccjbk0JX.o: In function `__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned int)':
q2.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE10deallocateEPij[__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned int)]+0xd): undefined reference to `operator delete(void*)'
/tmp/ccjbk0JX.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
/tmp/ccjbk0JX.o:(.eh_frame+0xa7): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

我无法理解这个错误。请帮忙。

4

1 回答 1

0

当您尝试使用 gcc 编译 C++ 代码时,通常会出现该错误,尝试使用 g++。如果仍然失败,请尝试传递 -lstdc++ (例如 g++ main.c -lstdc++ )。

于 2013-09-25T05:25:39.310 回答