Method 'cend' could not be resolved, but build is successful [message #1732909] |
Sun, 22 May 2016 17:24 |
David Frager Messages: 2 Registered: May 2016 |
Junior Member |
|
|
I am attempting to setup Eclipse for C/C++, and I am seeing an issue when testing my configuration.
I have a very basic C++ program using vectors, and in the IDE, I see errors indicating that "Method 'cend' could not be resolved. However, If I do a build, my build is successful.
a small portion of the code is:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <vector>
std::vector<std::string> tokenize(const std::string& s, char c) {
auto end = s.cend();
auto start = end;
std::vector<std::string> v;
for( auto it = s.cbegin(); it != end; ++it ) {
if( *it != c ) {
if( start == end )
start = it;
continue;
}
if( start != end ) {
v.emplace_back(start, it);
start = end;
}
}
if( start != end )
v.emplace_back(start, end);
return v;
}
|
|
|
Re: Method 'cend' could not be resolved, but build is successful [message #1732965 is a reply to message #1732909] |
Mon, 23 May 2016 06:21 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
You should avoid using auto to declare variables this way. It's OK for loops and function results but auto originally was a storage class (the opposite of static) . This changed with C++11. You seem to be using C++11. The compiler warns about using auto -- with C++98 anyway.
Although it's legal, sometimes the indexer gets confused by auto constructs.
using std::string::const_iterator end = s.cend(); might fix the problem..
Give it a try and let us know if it didn't.
[Updated on: Mon, 23 May 2016 12:55] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02841 seconds