Доброго дня. Вопрос: как обращатся к открытым членам класса из deque? Код:
| Код | #include <iostream> #include <string> #include <deque> #include <algorithm>
class Person { public: Person(const std::string a, const std::string b) { name = a; surname = b; }
std::string name; std::string surname; };
bool PersonSort(const Person& p1, const Person& p2) { return p1.surname < p2.surname || !(p2.surname < p1.surname) && p1.name < p2.name; }
void main() { std::deque<Person> coll; coll.push_back(Person("Robert", "Sheckley")); coll.push_back(Person("Harry", "Harrison"));
std::sort(coll.begin(), coll.end(), PersonSort);
std::deque<Person>::const_iterator pos; pos = coll.begin(); std::cout<<*pos->name<<' '<<*pos->surname<<'\n';//2 error-а : error C2100: illegal indirection *(++pos); std::cout<<*pos->name<<' '<<*pos->surname<<'\n';//2 error-а : error C2100: illegal indirection
}
|
Дает четыре ошибки.(в комментах написано) Что я делаю не так? И как правильно? |