【发布时间】:2012-06-13 04:49:59
【问题描述】:
尝试通过std::vector 构造函数初始化指向NULL 的指针向量时遇到编译错误。我简化了说明以使其简单:
vector<int*> v (100,NULL)
我猜这与const T& value= T()(构造函数的参数)和NULL值之间的不兼容有关,但我希望能得到进一步的解释。
谢谢
【问题讨论】:
-
“执行错误”?错误是什么?您是否在调试器中运行它以确认是这条线失败了?
-
不,我没有使用调试器(我是个新手)。另外,这不是执行而是编译错误,我错了。给你: ArbreN.hpp:55:3: 警告:将 NULL 传递给 'std::vector<_tp _alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = int, _Tp = ArbreNari
::node_arbreNari*, _Alloc = std::allocator ::node_arbreNari*>, std::vector<_tp _alloc>::allocator_type = std::allocator ::node_arbreNari*>]' [-Wconversion-null] -
顺便说一下,如果你使用单参数构造函数(
vector<int *> v(100);,它们会自动初始化为NULL。 -
我无法在 ideone (link) 上重现警告。
-
当询问一段特定的无法编译的代码时,请确保包含编译器错误消息。虽然有时很复杂,但它们通常包含有助于确定问题原因的重要信息。
标签: c++ pointers null stdvector