C++中vector元素的類型為指針,如何將其賦為NULL?vector<int*> p(5, NULL); 這段代碼能被最新的g++編譯,但在某些老版本的g++中,會給出如下錯誤信息: warning: passing NULL to non-pointer argument 2 of "std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [wit- _InputIterator = int, _Tp = int*, _Alloc = std::allocator<int*>, allocator_type = std::allocator<int*>]"In file included from /usr/include/c++/4.5/vector:65:0, ……1 個答案
答案 1:
null 是const int,與int* 指針類型不符合 轉一下就可以了: std::vector<int*> v1(5,static_cast<int*>(0));