initialize vector of pointers (automatically)

▼魔方 西西 提交于 2019-12-06 05:26:12

If you have the relevant C++11 support, you could use nullptr:

std::vector<int*> v(100, nullptr);

However, in your particular case, there is no need to specify a default value, so the following would suffice:

std::vector<int*> v(100);

NULL is likely defined as 0, so you end up with

vector<int*> v(100,0);

which tries to build a vector of ints, not of int*s.

Just skip the NULL, as that is default for pointers anyway, or cast it to the correct pointer type (int*)NULL.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!