#include <iostream>
using namespace std;
struct whatever
{
int liczba;
bool operator < (whatever a, whatever b)
{
return (a.liczba<b.liczba);
}
};
int main()
{
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
return 0;
}
Się nawet nie kompiluje:
prog.cpp:7:44: error: ‘bool whatever::operator<(whatever, whatever)’ must take exactly one argument
bool operator < (whatever a, whatever b)
^
prog.cpp: In function ‘int main()’:
prog.cpp:15:65: error: no match for ‘operator<’ (operand types are ‘whatever’ and ‘whatever’)
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
^
prog.cpp:15:65: note: candidates are:
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from prog.cpp:1:
/usr/include/c++/4.8/bits/stl_pair.h:220:5: note: template<class _T1, class _T2> bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/include/c++/4.8/bits/stl_pair.h:220:5: note: template argument deduction/substitution failed:
prog.cpp:15:66: note: ‘whatever’ is not derived from ‘const std::pair<_T1, _T2>’
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from prog.cpp:1:
/usr/include/c++/4.8/bits/stl_iterator.h:297:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator<(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:297:5: note: template argument deduction/substitution failed:
prog.cpp:15:66: note: ‘whatever’ is not derived from ‘const std::reverse_iterator<_Iterator>’
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from prog.cpp:1:
/usr/include/c++/4.8/bits/stl_iterator.h:347:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator<(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:347:5: note: template argument deduction/substitution failed:
prog.cpp:15:66: note: ‘whatever’ is not derived from ‘const std::reverse_iterator<_Iterator>’
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from prog.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2569:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2569:5: note: template argument deduction/substitution failed:
prog.cpp:15:66: note: ‘whatever’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from prog.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2581:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2581:5: note: template argument deduction/substitution failed:
prog.cpp:15:66: note: ‘whatever’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from prog.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2593:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const _CharT* __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2593:5: note: template argument deduction/substitution failed:
prog.cpp:15:66: note: mismatched types ‘const _CharT*’ and ‘whatever’
whatever a; a.liczba=20; whatever b; b.liczba=25; cout << (a<b);
^
WTF??? Co to znaczy: "error: ‘bool whatever::operator<(whatever, whatever)’ must take exactly one argument"???
Jak to: JEDEN ARGUMENT? Jak żesz mam porównywać JEDEN ARGUMENT?!? Co, mam porównywać strukturę samą ze sobą? O ile mi wiadomo, operator < jest operatorem binarnym, nie unarnym, czy tak?
Zatem: Jak mam go przeładować, żeby nie wyskakiwał błąd?
Z góry dzięki.