![]() |
|
Модераторы: Daevaorn |
![]()
|
|
| AlexanderV |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 49 Регистрация: 31.8.2005 Где: Украина, Киев Репутация: нет Всего: нет |
В общеми, есть код вроде этого:
Две аналогичные структуры s1 и s2, s2 вложена в s1. В похожих функциях v1 и v2 создается STL-список с типом s1 и s2 соответственно, а потом сортируеться через алгоритм sort. Используеться функтор greater, причем оператор сравнения > перегружен в обоих случаях. Проблема в том, что v2 не компилируеться, выдавая абсолютно бредовую оишбку 11 раз: Как исправить ситуацию? /////////////////////////////////// c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::basic_string<_E,_Tr,_A> &,const _E *)' : could not deduce template argument for 'const class std::basic_string<_E,_Tr,_A> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const _E *,const class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'const *' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::basic_string<_E,_Tr,_A> &,const class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'const class std:: basic_string<_E,_Tr,_A> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::multimap<_K,_Ty,_Pr,_A> &,const class std::multimap<_K,_Ty,_Pr,_A> &)' : could not deduce template argument for 'const class std:: multimap<_K,_Ty,_Pr,_A> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::map<_K,_Ty,_Pr,_A> &,const class std::map<_K,_Ty,_Pr,_A> &)' : could not deduce template argument for 'const class std::map<_K,_Ty ,_Pr,_A> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::_Tree<_K,_Ty,_Kfn,_Pr,_A> &,const class std::_Tree<_K,_Ty,_Kfn,_Pr,_A> &)' : could not deduce template argument for 'const class s td::_Tree<_K,_Ty,_Kfn,_Pr,_A> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::vector<_Ty,_A> &,const class std::vector<_Ty,_A> &)' : could not deduce template argument for 'const class std::vector<_Ty,_A> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::list<_Ty,_A> &,const class std::list<_Ty,_A> &)' : could not deduce template argument for 'const class std::list<_Ty,_A> &' from ' const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce template argum ent for 'const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2784: 'bool __cdecl std::operator >(const struct std::pair<_T1,_T2> &,const struct std::pair<_T1,_T2> &)' : could not deduce template argument for 'const struct std::pair<_T1,_T2> &' from 'const struct s1::s2' c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' c:\microsoftprograms\studio6\vc98\include\functional(80) : error C2676: binary '>' : 'const struct s1::s2' does not define this operator or a conversion to a type acceptable to the predefined operator c:\microsoftprograms\studio6\vc98\include\functional(80) : while compiling class-template member function 'bool __thiscall std::greater<struct s1::s2>::operator ()(const struct s1::s2 &,const struct s1::s2 &) const' //////////////////////////////////////////////////// |
|||
|
||||
| MAKCim |
|
|||
![]() Воін дZэна ![]() ![]() ![]() ![]() Профиль Группа: Экс. модератор Сообщений: 5644 Регистрация: 10.12.2005 Где: Менск, РБ Репутация: 52 Всего: 207 |
у g++ 4.0.2 все OK
(copy-paste как здесь) -------------------- Ах, у елі, ах, у ёлкі, ах, у елі злыя волкі © |
|||
|
||||
| AlexanderV |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 49 Регистрация: 31.8.2005 Где: Украина, Киев Репутация: нет Всего: нет |
У меня MSVC++ 6.0
|
|||
|
||||
| likehood |
|
|||
|
666 ![]() ![]() Профиль Группа: Участник Сообщений: 536 Регистрация: 21.12.2005 Репутация: 8 Всего: 24 |
||||
|
||||
| AlexanderV |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 49 Регистрация: 31.8.2005 Где: Украина, Киев Репутация: нет Всего: нет |
А какие у тебя библиотеки подключены?
(Если можно, лучше выложи кодом всю верхнюю часть файла Какой тип приложения выставлен? |
|||
|
||||
| likehood |
|
|||
|
666 ![]() ![]() Профиль Группа: Участник Сообщений: 536 Регистрация: 21.12.2005 Репутация: 8 Всего: 24 |
Тип приложения: Win32 Console.
Вот заголовок:
|
|||
|
||||
| AlexanderV |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 49 Регистрация: 31.8.2005 Где: Украина, Киев Репутация: нет Всего: нет |
Все равно у меня эта пакость не работает
Выложи, пожалуйста, на форум полностью свой компилирующийся проект с этими двумя структурами, буду смотреть, где я уже у себя в настройках что подхимичил... |
|||
|
||||
| likehood |
|
|||
|
666 ![]() ![]() Профиль Группа: Участник Сообщений: 536 Регистрация: 21.12.2005 Репутация: 8 Всего: 24 |
Попробуй просто создать новый проект и забей туда только этот код, ничего лишнего. Если не поможет, значит что-то с студией у тебя не так.
|
|||
|
||||
| MAKCim |
|
||||||
![]() Воін дZэна ![]() ![]() ![]() ![]() Профиль Группа: Экс. модератор Сообщений: 5644 Регистрация: 10.12.2005 Где: Менск, РБ Репутация: 52 Всего: 207 |
а не
случайно? -------------------- Ах, у елі, ах, у ёлкі, ах, у елі злыя волкі © |
||||||
|
|||||||
| AlexanderV |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 49 Регистрация: 31.8.2005 Где: Украина, Киев Репутация: нет Всего: нет |
Да это я уже пробовал, не помогает... Выложи все-таки свой проjект, толку больше будет... |
|||
|
||||
| likehood |
|
|||
|
666 ![]() ![]() Профиль Группа: Участник Сообщений: 536 Регистрация: 21.12.2005 Репутация: 8 Всего: 24 |
Высылаю файл проекта. Раньше не мог, потому что на работе у меня не стоит VC6, домой пришел только что.
Кстати, MAKCim, строчка #include <functional> необязательна, т.к. она уже есть в файле list. Присоединённый файл ( Кол-во скачиваний: 4 )
debug.dsp 3,31 Kb |
|||
|
||||
| Earnest |
|
|||
![]() Эксперт ![]() ![]() ![]() ![]() Профиль Группа: Экс. модератор Сообщений: 5962 Регистрация: 17.6.2005 Где: Рязань Репутация: 53 Всего: 183 |
Возможно, в результате какого-то другого кода (или подключенных файлов) компилятор в упор не видит операторы >. Судя по первой ошибке, он, бедняга, пытается использовать оператор для сравнения строк.
Попробуй заменить внешние дружественные операторы > на константные операторы-члены >. По-моему, должно скомпилироваться. -------------------- ... |
|||
|
||||
| AlexanderV |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 49 Регистрация: 31.8.2005 Где: Украина, Киев Репутация: нет Всего: нет |
Переустановил Visual Studio, все проблемы как рукой сняло
Всем спасибо. |
|||
|
||||
![]()
|
| Правила форума "С++:Общие вопросы" | |
|
|
Добро пожаловать!
Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Earnest Daevaorn |
| 0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей) | |
| 0 Пользователей: | |
| « Предыдущая тема | C/C++: Общие вопросы | Следующая тема » |
|
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |