I'm trying to do
remove(pvec.begin(), pvec.end(), NULL);
Run Code Online (Sandbox Code Playgroud)
to remove NULL pointers in the vector (where pvec is vector<Node*>)
However, the compiler gives:
"ISO C++ forbids comparison between pointer and integer"
How to resolve this? Thanks!
And*_*owl 16
In C++11, use nullptr:
remove(pvec.begin(), pvec.end(), nullptr);
// ^^^^^^^
Run Code Online (Sandbox Code Playgroud)
Otherwise, perform an explicit cast to a pointer value. If your pvec contains pointers of type foo*, write:
remove(pvec.begin(), pvec.end(), static_cast<foo*>(NULL));
// ^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
738 次 |
| 最近记录: |