Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I'm trying to do
remove(pvec.begin(), pvec.end(), NULL);
to remove NULL pointers in the vector (where pvec is vector<Node*>)
vector<Node*>
However, the compiler gives:
"ISO C++ forbids comparison between pointer and integer"
How to resolve this? Thanks!
In C++11, use nullptr:
nullptr
remove(pvec.begin(), pvec.end(), nullptr); // ^^^^^^^
Otherwise, perform an explicit cast to a pointer value. If your pvec contains pointers of type foo*, write:
pvec
foo*
remove(pvec.begin(), pvec.end(), static_cast<foo*>(NULL)); // ^^^^^^^^^^^^^^^^^
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.