The elements of nodes
is the pointer to Node
, not Node
. So, you should use std::find_if
.
nodePosition = find_if(nodes.begin(), nodes.end(),
[nodeId](Node *p) { return *p == nodeId; });
PS. Although c++11
is the tag of your question, you didn't use any nice features of C++11!
PS2. Notice your first example with vector<Node>
will occur slicing problem.
PS3. And in your first example, you need not and should not use new
. just nodes.push_back(Node(22));
or nodes.emplace_back(22);
.