I have tried several ways of iterating over my "entries" map, but all of them produce the same lengthy error message.
dylan@Aspire-one:~$ g++ -std=c++11 dictionary.cpp
In file included from /usr/include/c++/4.8/map:60:0,
from dictionary.h:6,
from dictionary.cpp:1:
/usr/include/c++/4.8/bits/stl_tree.h: In instantiation of ‘void
std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare,
_Alloc>::_M_insert_unique(_II, _II) [with _InputIterator =
std::basic_string<char>; _Key = std::basic_string<char>; _Val =
std::pair<const std::basic_string<char>, std::basic_string<char> >;
_KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char>,
std::basic_string<char> > >; _Compare = std::less<std::basic_string<char>
>; _Alloc = std::allocator<std::pair<const std::basic_string<char>,
std::basic_string<char> > >]’:
/usr/include/c++/4.8/bits/stl_map.h:226:11: required from
‘std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator,
_InputIterator) [with _InputIterator = std::basic_string<char>; _Key =
std::basic_string<char>; _Tp = std::basic_string<char>; _Compare =
std::less<std::basic_string<char> >; _Alloc =
std::allocator<std::pair<const std::basic_string<char>,
std::basic_string<char> > >]’
dictionary.h:11:66: required from here
/usr/include/c++/4.8/bits/stl_tree.h:1721:28: error: no match for
‘operator++’ (operand type is ‘std::basic_string<char>’)
for (; __first != __last; ++__first)
^
/usr/include/c++/4.8/bits/stl_tree.h:1722:29: error: no match for
‘operator*’ (operand type is ‘std::basic_string<char>’)
_M_insert_unique_(end(), *__first);
^
dylan@Aspire-one:~$
Here is my most recent code.
dictionary.cpp
#include "dictionary.h"
//I have included <string> <map> <iterator> "from dictionary.h"
bool dictionary::search_term(const std::string& term){
std::map<std::string, std::string>::iterator it;
for (it = entries.begin(); it != entries.end(); ++it){
if(it->first != term);
else return true;
}return false;
};
So the error is in "dictionary.h"?
dictionary.h
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include <iterator>
#include <string>
#include <map>
class dictionary{
public:
dictionary(const std::string& title, const std::string& definition = "")
: entries(std::map<std::string, std::string>(title, definition)){;};
bool write_entry(const std::string& term, const std::string& definition = "");
bool define_term(const std::string& term, const std::string& definition);
bool erase_entry(const std::string& term);
bool search_term(const std::string& term);
private:
std::map<std::string, std::string> entries;
};
#endif//DICTIONARY_H
Aucun commentaire:
Enregistrer un commentaire