The code I'm trying to run:
std::string genBlankName(std::vector<Post> &posts)
{
std::string baseName = "New Post ";
int postNum = 1;
for (std::vector<Post>::iterator currentPost = posts.begin(); currentPost != posts.end(); currentPost++)
{
if (posts[currentPost].name.substr(0, baseName.length()) == baseName &&
utils::is_num(posts[currentPost].name.substr(baseName.length(), std::string::npos)) &&
utils::to_int(posts[currentPost].name.substr(baseName.length(), std::string::npos)) > postNum)
{
postNum = utils::to_int(posts[currentPost].name.substr(baseName.length(), std::string::npos));
}
}
return baseName + utils::to_string(postNum);
}
And the error I get:
/home/brett/projects/CLPoster/CLPoster-build-desktop/../CLPoster/item.h:240: error: no matching function for call to
std::vector<cl::Post, std::allocator<cl::Post> >::at(__gnu_cxx::__normal_iterator<cl::Post*, std::vector<cl::Post, std::allocator<cl::Post> > >&)
Sorry for not saying more, but I'm assuming this is a pretty common thing I'm just unaware of being a nub. I'd google it, but it seems too general of a problem to turn up anything useful as I suspect it's more of a problem with my implementation or something along those lines.
Subscripting requires the use of an index, you’re using iterators.
You don’t need subscript at all, just dereference your iterator:
currentPost->name.substr(0, baseName.length())
… and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With