I'm working through Accelerated C++ by Andrew Koenig and Barbara Moo. In chapter 7, they talk about associative containers. One example is representing grammar rules programmatically. I'm following the example from the book, and the book is supposed to be for C++11. I have also set my compiler in CLion to be C++11. But I see red squigglies. In particular, given the following code, I can't seem to be able to push back a new Rule initialized with the entry's beginning and end values (look at the comment where it says why that's a compile-time error) - it says parameter type mismatch between unsigned long and iterator
. Any ideas?
/* Typedefs representing our rules for sentence generations */
typedef std::vector<std::string> Rule;
typedef std::vector<Rule> RuleCollection;
typedef std::map<std::string, RuleCollection> Grammar;
/* Forward declarations */
std::vector<std::string> split(std::string);
Grammar read_grammar(std::istream &in) {
Grammar grammar;
std::string line;
while (getline(in, line)) {
std::vector<std::string> entry = split(line);
if (!entry.empty()) {
// Use the category to store the associated rule
// Why is this an error?
// grammar[entry[0]].push_back(Rule(entry.begin() + 1, entry.end()));
}
}
return grammar;
}
Aucun commentaire:
Enregistrer un commentaire