Reputation: 23
I have a piece of code as follows:
#include<algorithm>
#include<vector>
std::vector<std::string> vect;
std::vector<std::string> * vectP;
vect.push_back("ele0");
vect.push_back("ele1");
void func(){
if(std::find(*vectP.begin(),*vecP.end(),"ele0")!=*vectP.end())
//'begin' and 'end' have not been declared
}
Why are begin
and end
not declared when they're used with pointers? *vectP
should be treated as if it's vect
since it's dereferenced, or have I misunderstood something? How should I rectify this?
Upvotes: 2
Views: 83
Reputation: 476990
You got your operator precedence wrong. *vectP.begin()
means *(vectP.begin())
(which doesn't work, of course), not (*vectP).begin()
, which is what you mean. But you should probably spell that vectP->begin()
.
Upvotes: 6