I am transferring something from another language to C++, as a complete beginner to C++ and I am trying to learn some essentials around struct creation and use in maps. I have this sketched below:
struct Cubic {
int X, Y, Z;
Cubic Neighbor(int);
};
struct Space{
Cubic location;
bool open;
bool blocked;
};
class Table {
int bound;
Cubic center;
std::map<Cubic, Space> grid;
Table* New(int, Cubic);
};
std::map<Cubic, Space> Allocate(int bound, Cubic center)
{
std::map<Cubic, Space> ret;
for (int x = -bound; x <= bound; x++) {
for (int y = std::max(-bound, -x-bound); y <= std::min(bound, -x+bound); y++) {
int z = -x - y;
Cubic cb = CubicAdd(center, {x, y, z});
ret[cb] = {location: cb, open: true}; //THIS IS A HUGE ERROR, see below
};
};
return ret;
}
It is basically a table cubic coordinates for hexagons. The other code can be posted, but it is not relevant to the matter at hand; i.e. it works in there and I have no problems understanding that, the issue is in trying to get to an understanding of basic C++ coding, which here is a map of Cubic structs keys to Space pointers embedded in a class Table....which I have not even gotten to instantiating yet.
Error:
doing
c++ table.cc -std=c++0x (for 2 files I have table.h & table.cc) generates this:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Cubic]’:
/usr/include/c++/4.8/bits/stl_map.h:463:31: required from ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = Cubic; _Tp = Space; _Compare = std::less<Cubic>; _Alloc = std::allocator<std::pair<const Cubic, Space> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = Space; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = Cubic]’
table.cc:63:13: required from here
/usr/include/c++/4.8/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const Cubic’ and ‘const Cubic’)
{ return __x < __y; }
^
/usr/include/c++/4.8/bits/stl_function.h:235:20: 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/stl_tree.h:61,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_pair.h:220:5: note: template<class _T1, class _T2> constexpr 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:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::pair<_T1, _T2>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/stl_tree.h:61,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc: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:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/stl_tree.h:61,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc: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:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/stl_tree.h:61,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_iterator.h:1055:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator<(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:1055:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/stl_tree.h:61,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_iterator.h:1061:5: note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator<(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:1061:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/map:60:0,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_tree.h:917:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^
/usr/include/c++/4.8/bits/stl_tree.h:917:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/bits/stl_map.h:63,
from /usr/include/c++/4.8/map:61,
from table.h:3,
from table.cc: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:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/bits/stl_map.h:63,
from /usr/include/c++/4.8/map:61,
from table.h:3,
from table.cc: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:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/bits/stl_map.h:63,
from /usr/include/c++/4.8/map:61,
from table.h:3,
from table.cc: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:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: mismatched types ‘const _CharT*’ and ‘Cubic’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/tuple:39:0,
from /usr/include/c++/4.8/bits/stl_map.h:63,
from /usr/include/c++/4.8/map:61,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/array:238:5: note: template<class _Tp, long unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
^
/usr/include/c++/4.8/array:238:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::array<_Tp, _Nm>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/bits/stl_map.h:63:0,
from /usr/include/c++/4.8/map:61,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/tuple:824:5: note: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Args1 ...>&, const std::tuple<_Args2 ...>&)
operator<(const tuple<_TElements...>& __t,
^
/usr/include/c++/4.8/tuple:824:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::tuple<_Args1 ...>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/map:61:0,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_map.h:979:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/4.8/bits/stl_map.h:979:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/map:62:0,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_multimap.h:881:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/4.8/bits/stl_multimap.h:881:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/map:60,
from table.h:3,
from table.cc:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Cubic’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
{ return __x < __y; }
^
You didn't post a definition of Cubic, but the issue is from the first error:
/usr/include/c++/4.8/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Cubic]’:
/usr/include/c++/4.8/bits/stl_map.h:463:31: required from ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = Cubic; _Tp = Space; _Compare = std::less<Cubic>; _Alloc = std::allocator<std::pair<const Cubic, Space> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = Space; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = Cubic]’
table.cc:63:13: required from here
/usr/include/c++/4.8/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const Cubic’ and ‘const Cubic’)
{ return __x < __y; }
^
std::map is a binary tree (red-black tree specifically) and it needs its keys to be LessThanComparable. By default, this uses operator< and your Key (Cubic) does not have a member or non-member operator< defined. The rest of the compile error is the compiler trying to stick Cubic into all the other operator<'s that it can find for any other type - none of which apply since Cubic isn't convertible to any of those.
So either provide one:
bool operator<(const Cubic& a, const Cubic& b) {
// something reasonable, probably like
return std::tie(a.X, a.Y, a.Z) < std::tie(b.X, b.Y, b.Z);
}
Or provide your map with a custom comparator:
struct CubicCompare {
bool operator()(const Cubic& a, const Cubic& b) const {
// something reasonable, return true if a is "less than" b
}
};
std::map<Cubic, Space, CubicCompare> ret;
std::map<> needs comparison operators to sort and order its data. By default, it uses the < operator. Looking at your errors, it looks like such an operator is not implemented in your Cubic class. You can solve this problem by overloading < in your Cubic class or use a custom comparator.
Heres info for a custom comparator.
Heres info for operator overloading.
Related
This question already has answers here:
Error using custom operator< with std::less
(2 answers)
Closed 4 years ago.
I want to define a static map inside a class, which will have a structure as both it's key and value. I've read that a '<' operator is needed to be defined, therefore I've included that definition inside the struct itself(I've randomly defined it as I don't need any comparison anywhere in my program).
The below sample code doesn't compile.The compiler produces a lot of warnings and errors which I don't understand right now. (Please ignore the uninitialized values in the main function):
#include<string>
#include<iostream>
#include<map>
using namespace std;
struct RJNodeAddress
{
string m_ip;
string m_port;
bool operator<(const RJNodeAddress &l)
{
int l_size=l.m_ip.size();
int r_size=l.m_port.size();
return (l_size < r_size);
}
};
struct RJNodeDetails
{
string m_NodeType;
int m_appId;
};
class RJWebsocket
{
public:
static map<RJNodeAddress,RJNodeDetails> m_Nodes;
};
int main()
{
RJNodeAddress l_node;
RJNodeDetails l_nodeDetails = RJWebsocket::m_Nodes[l_node];
}
Compiler output
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h: In instantiation of âconstexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = RJNodeAddress]â:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:491:32: required from âstd::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = RJNodeAddress; _Tp = RJNodeDetails; _Compare = std::less<RJNodeAddress>; _Alloc = std::allocator<std::pair<const RJNodeAddress, RJNodeDetails> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = RJNodeDetails; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = RJNodeAddress]â
test.cpp:34:59: required from here
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: error: no match for âoperator<â (operand types are âconst RJNodeAddressâ and âconst RJNodeAddressâ)
{ return __x < __y; }
~~~~^~~~~
test.cpp:10:14: note: candidate: bool RJNodeAddress::operator<(const RJNodeAddress&) <near match>
bool operator<(const RJNodeAddress &l)
^~~~~~~~
test.cpp:10:14: note: passing âconst RJNodeAddress*â as âthisâ argument discards qualifiers
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:64:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_pair.h:449:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_pair.h:449:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::pair<_T1, _T2>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:305:5: note: candidate: template<class _Iterator> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator<(const reverse_iterator<_Iterator>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:305:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::reverse_iterator<_Iterator>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:343:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator<(const reverse_iterator<_IteratorL>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:343:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::reverse_iterator<_Iterator>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1142:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
operator<(const move_iterator<_IteratorL>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1142:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::move_iterator<_IteratorL>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1148:5: note: candidate: template<class _Iterator> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
operator<(const move_iterator<_Iterator>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1148:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::move_iterator<_IteratorL>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:485:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::basic_string_view<_CharT, _Traits>)
operator< (basic_string_view<_CharT, _Traits> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:485:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:491:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::__detail::__idt<std::basic_string_view<_CharT, _Traits> >)
operator< (basic_string_view<_CharT, _Traits> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:491:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:497:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::__detail::__idt<std::basic_string_view<_CharT, _Traits> >, std::basic_string_view<_CharT, _Traits>)
operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:497:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5892:5: note: candidate: 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,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5892:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::basic_string<_CharT, _Traits, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5905:5: note: candidate: 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,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5905:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::basic_string<_CharT, _Traits, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5917:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const _CharT* __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5917:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: mismatched types âconst _CharT*â and âRJNodeAddressâ
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/ios_base.h:46:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/ios:42,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/ostream:38,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/iostream:39,
from test.cpp:2:
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:208:3: note: candidate: bool std::operator<(const std::error_code&, const std::error_code&)
operator<(const error_code& __lhs, const error_code& __rhs) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:208:3: note: no known conversion for argument 1 from âconst RJNodeAddressâ to âconst std::error_code&â
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:282:3: note: candidate: bool std::operator<(const std::error_condition&, const std::error_condition&)
operator<(const error_condition& __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:282:3: note: no known conversion for argument 1 from âconst RJNodeAddressâ to âconst std::error_condition&â
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:808:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const std::optional<_Up>&)
operator<(const optional<_Tp>& __lhs, const optional<_Up>& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:808:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:861:5: note: candidate: template<class _Tp> constexpr bool std::operator<(const std::optional<_Tp>&, std::nullopt_t)
operator<(const optional<_Tp>& /* __lhs */, nullopt_t) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:861:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:866:5: note: candidate: template<class _Tp> constexpr bool std::operator<(std::nullopt_t, const std::optional<_Tp>&)
operator<(nullopt_t, const optional<_Tp>& __rhs) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:866:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:926:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const _Up&)
operator<(const optional<_Tp>& __lhs, const _Up& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:926:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:932:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Up>() < declval<_Tp>()))> std::operator<(const _Up&, const std::optional<_Tp>&)
operator<(const _Up& __lhs, const optional<_Tp>& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:932:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:40,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/array:262:5: note: candidate: template<class _Tp, long unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/array:262:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::array<_Tp, _Nm>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:40:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:1410:5: note: candidate: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Tps ...>&, const std::tuple<_Elements ...>&)
operator<(const tuple<_TElements...>& __t,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:1410:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::tuple<_Tps ...>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:1543:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:1543:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:61:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:1397:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:1397:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::map<_Key, _Tp, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:62:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_multimap.h:1062:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_multimap.h:1062:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::multimap<_Key, _Tp, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
As keys in std::map are const your operator< method must be const as well:
bool operator<(const RJNodeAddress &l) const
// ^ here
it should be const anyway as it does not modify the object but in this case missing it leads to compilation errors.
My issue is in the following .h:
#include <iostream>
#include <map>
#include <vector>
struct Node {
int data;
};
class Graph {
std::map< Node, std::vector<Node> > edge_map;
public:
Graph();
void add_neighbor(Node cur_node, Node new_node);
void remove_neighbor(Node cur_node, Node del_node);
virtual ~Graph();
};
and in trying to implement the add_neighbor function, but I'm fumbling through the details and need some direction. What I've got so far (not functional) is the following:
void Graph::add_neighbor(Node cur_node, Node new_node) {
if (edge_map.find(cur_node) == edge_map.end()) {
edge_map.insert(std::pair<Node, std::vector<Node> >(cur_node, std::vector<Node>()));
edge_map[cur_node].push_back(new_node);
}
else {
edge_map[cur_node].push_back(new_node);
}
}
I can copy the explosion that g++ -std=c++11 throws at me, but it's not very helpful. How can I include a map as a class member where the key, value are struct, vector of struct, and then have a function in the .cpp that can add it? I'll also need the remove function, but once I understand how to treat the data in the insertion function I'll know what I need, I think.
EDIT (including the compiler vomit):
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Node]’:
/usr/include/c++/4.8/bits/stl_map.h:463:31: required from ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = Node; _Tp = std::vector<Node>; _Compare = std::less<Node>; _Alloc = std::allocator<std::pair<const Node, std::vector<Node> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::vector<Node>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = Node]’
graph.cpp:14:26: required from here
/usr/include/c++/4.8/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const Node’ and ‘const Node’)
{ return __x < __y; }
^
/usr/include/c++/4.8/bits/stl_function.h:235:20: 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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_pair.h:220:5: note: template<class _T1, class _T2> constexpr 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:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::pair<_T1, _T2>’
{ return __x < __y; }
^
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 graph.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:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
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 graph.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:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_iterator.h:1055:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator<(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:1055:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_iterator.h:1061:5: note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator<(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:1061:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
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 graph.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:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
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 graph.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:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
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 graph.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:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: mismatched types ‘const _CharT*’ and ‘Node’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/vector:64:0,
from graph.cpp:2:
/usr/include/c++/4.8/bits/stl_vector.h:1421:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/4.8/bits/stl_vector.h:1421:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::vector<_Tp, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/tuple:39:0,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/bits/stl_algo.h:66,
from /usr/include/c++/4.8/algorithm:62,
from graph.cpp:3:
/usr/include/c++/4.8/array:238:5: note: template<class _Tp, long unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
^
/usr/include/c++/4.8/array:238:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::array<_Tp, _Nm>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/functional:55:0,
from /usr/include/c++/4.8/bits/stl_algo.h:66,
from /usr/include/c++/4.8/algorithm:62,
from graph.cpp:3:
/usr/include/c++/4.8/tuple:824:5: note: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
operator<(const tuple<_TElements...>& __t,
^
/usr/include/c++/4.8/tuple:824:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::tuple<_Elements ...>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/map:60:0,
from graph.h:2,
from graph.cpp:4:
/usr/include/c++/4.8/bits/stl_tree.h:917:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^
/usr/include/c++/4.8/bits/stl_tree.h:917:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/map:61:0,
from graph.h:2,
from graph.cpp:4:
/usr/include/c++/4.8/bits/stl_map.h:979:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/4.8/bits/stl_map.h:979:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8/map:62:0,
from graph.h:2,
from graph.cpp:4:
/usr/include/c++/4.8/bits/stl_multimap.h:881:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/4.8/bits/stl_multimap.h:881:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/string:48: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 graph.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h:235:20: note: ‘const Node’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
{ return __x < __y; }
^
In order for std::map to order it's entrys, it requires an operator<.
In your case, it can be as simple as this:
bool operator<(const Node & left, const Node & right)
{
return left.data < right.data;
}
This is for a single error. I had to cut it down in order to post it here. How to disable this madness ? (g++ 5.3.1)
user#computer:~/projectClient# ./build
project/update.cpp: In function ‘bool is_recentlyProcessed(IntervalTime, ulong)’:
project/update.cpp:71:80: error: no match for ‘operator==’ (operand types are ‘std::_Rb_tree_const_iterator<long unsigned int>’ and ‘std::map<IntervalTime, std::set<long unsigned int> >::iterator {aka std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > >}’)
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/set:60:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_tree.h:312:7: note: candidate: bool std::_Rb_tree_const_iterator<_Tp>::operator==(const _Self&) const [with _Tp = long unsigned int; std::_Rb_tree_const_iterator<_Tp>::_Self = std::_Rb_tree_const_iterator<long unsigned int>]
operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/5/bits/stl_tree.h:312:7: note: no known conversion for argument 1 from ‘std::map<IntervalTime, std::set<long unsigned int> >::iterator {aka std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > >}’ to ‘const _Self& {aka const std::_Rb_tree_const_iterator<long unsigned int>&}’
In file included from /usr/include/c++/5/stack:61:0,
from /usr/include/jsoncpp/json/reader.h:15,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_stack.h:246:5: note: candidate: template<class _Tp, class _Seq> bool std::operator==(const std::stack<_Tp, _Seq>&, const std::stack<_Tp, _Seq>&)
operator==(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y)
^
/usr/include/c++/5/bits/stl_stack.h:246:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::stack<_Tp, _Seq>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:2220:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator==(const std::deque<_Tp, _Alloc>&, const std::deque<_Tp, _Alloc>&)
operator==(const deque<_Tp, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:2220:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::deque<_Tp, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:272:5: note: candidate: template<class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> bool std::operator==(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _RefR, _PtrR>&)
operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:272:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:265:5: note: candidate: template<class _Tp, class _Ref, class _Ptr> bool std::operator==(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _Ref, _Ptr>&)
operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:265:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/map:62:0,
from /usr/include/jsoncpp/json/value.h:17,
from /usr/include/jsoncpp/json/json.h:10,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_multimap.h:974:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_multimap.h:974:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/map:61:0,
from /usr/include/jsoncpp/json/value.h:17,
from /usr/include/jsoncpp/json/json.h:10,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_map.h:1073:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_map.h:1073:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:347:5: note: candidate: template<class _Tp> bool std::operator==(std::nullptr_t, const std::shared_ptr<_Tp1>&)
operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
^
/usr/include/c++/5/bits/shared_ptr.h:347:5: note: template argument deduction/substitution failed:
project/update.cpp:71:15: note: cannot convert ‘std::find<std::_Rb_tree_const_iterator<long unsigned int>, long unsigned int>((& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::begin<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), (& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::end<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), id)’ (type ‘std::_Rb_tree_const_iterator<long unsigned int>’) to type ‘std::nullptr_t’
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:342:5: note: candidate: template<class _Tp> bool std::operator==(const std::shared_ptr<_Tp1>&, std::nullptr_t)
operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
^
/usr/include/c++/5/bits/shared_ptr.h:342:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::shared_ptr<_Tp1>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:336:5: note: candidate: template<class _Tp1, class _Tp2> bool std::operator==(const std::shared_ptr<_Tp1>&, const std::shared_ptr<_Tp2>&)
operator==(const shared_ptr<_Tp1>& __a,
^
/usr/include/c++/5/bits/shared_ptr.h:336:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::shared_ptr<_Tp1>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1194:5: note: candidate: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(std::nullptr_t, const std::__shared_ptr<_Tp, _Lp>&)
operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
^
/usr/include/c++/5/bits/shared_ptr_base.h:1194:5: note: template argument deduction/substitution failed:
project/update.cpp:71:15: note: cannot convert ‘std::find<std::_Rb_tree_const_iterator<long unsigned int>, long unsigned int>((& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::begin<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), (& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::end<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), id)’ (type ‘std::_Rb_tree_const_iterator<long unsigned int>’) to type ‘std::nullptr_t’
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1189:5: note: candidate: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp, _Lp>&, std::nullptr_t)
operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
^
/usr/include/c++/5/bits/shared_ptr_base.h:1189:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::__shared_ptr<_Tp, _Lp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1183:5: note: candidate: template<class _Tp1, class _Tp2, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp1, _Lp>&, const std::__shared_ptr<_Tp2, _Lp>&)
operator==(const __shared_ptr<_Tp1, _Lp>& __a,
^
/usr/include/c++/5/bits/shared_ptr_base.h:1183:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::__shared_ptr<_Tp1, _Lp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:62:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_multiset.h:825:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)
operator==(const multiset<_Key, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_multiset.h:825:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::multiset<_Key, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:61:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_set.h:842:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)
operator==(const set<_Key, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_set.h:842:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::set<_Key, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:60:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_tree.h:1273:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator==(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator==(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_tree.h:1273:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
....
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/allocator.h:134:5: note: candidate: template<class _Tp> bool std::operator==(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
^
/usr/include/c++/5/bits/allocator.h:134:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/allocator.h:128:5: note: candidate: template<class _T1, class _T2> bool std::operator==(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
operator==(const allocator<_T1>&, const allocator<_T2>&)
^
/usr/include/c++/5/bits/allocator.h:128:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/char_traits.h:40:0,
from /usr/include/c++/5/string:40,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/postypes.h:216:5: note: candidate: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^
/usr/include/c++/5/bits/postypes.h:216:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::fpos<_StateT>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1071:5: note: candidate: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator==(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1071:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::move_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1065:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator==(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1065:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::move_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:342:5: note: candidate: 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++/5/bits/stl_iterator.h:342:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:292:5: note: candidate: 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++/5/bits/stl_iterator.h:292:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/utility:70:0,
from /usr/include/c++/5/algorithm:60,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:214:5: note: candidate: template<class _T1, class _T2> constexpr 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++/5/bits/stl_pair.h:214:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::pair<_T1, _T2>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
from /usr/include/c++/5/bits/allocator.h:46,
from /usr/include/c++/5/string:41,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/ext/new_allocator.h:139:5: note: candidate: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
^
/usr/include/c++/5/ext/new_allocator.h:139:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:827:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
^
/usr/include/c++/5/bits/stl_iterator.h:827:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:820:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
^
/usr/include/c++/5/bits/stl_iterator.h:820:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
user#computer:~/projectClient#
Here's the build command (it doesn't make a difference if i remove -Wall):
g++ -O3 -Wall -Wno-deprecated-declarations -Wno-unused-variable -Wno-format-contains-nul -std=c++11 -D${JSON} \
-lpthread -lboost_system -lboost_chrono -lssl -lcrypto -ljsoncpp \
-o bin/client client.cpp common.cpp update.cpp
While the error spew is daunting at initial glance, it can be helpful in tricky cases. Just start at the top and work your way down until you figure out what the problem is.
In this case it looks like you're trying to compare a std::_Rb_tree_const_iterator<long unsigned int> with a std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > > which are iterators to completely different types of objects.
It seems that find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) returns an interator to a different container than what recentlyProcessed.end is - note that recentlyProcessed.end doesn't have an index.
Probably you need to compare with recentlyProcessed[it].end or recentlyProcessed[it].end() instead.
I'm perplexed by an error I'm getting with c++ using NetBeans. I'm not the best at pointers vs. non-pointers (native Java coder), so keep that in mind.
I'm working on a watered-down version of the "Netflix Challenge" for data structures in uni, and I'm on the final method of displaying the top n movies for each user. Below the code is the (copious) error message(s) I'm getting. It seems to say I'm using a less-than operator on a MovieBase::Movie, but I'm only using it on floats - and it states it's being called from the wrong line (I've marked it in comments).
In addition, the final cout << at the end is stating something about discarding qualifiers, and after searching around I still had no idea what it was trying to tell me.
Can anyone offer a little insight? Thank you!
map<MovieBase::Movie,float> UserBase::topMovieList(int moviesToShow, MovieBase* mb, unsigned int userID){
map<MovieBase::Movie,float> topList;
vector<MovieBase::Movie>::iterator mit = mb->allMovies.begin();
while(mit!=mb->allMovies.end()){
MovieBase::Movie thisMovie = *mit;
vector<string> theseGenres = thisMovie.getGenres();
float weightedScore = 0;
for(int i=0;i<theseGenres.size();i++){
weightedScore+=this->get(userID)->preferenceFactors.at(theseGenres[i])*(thisMovie.getAverage());
}
weightedScore = weightedScore/theseGenres.size();
if(topList.empty()){
map<MovieBase::Movie,float>::iterator bit = topList.begin();
//The error occurs on the line below
topList.insert(bit,std::make_pair(thisMovie,weightedScore));
}
else{
map<MovieBase::Movie,float>::iterator bit = topList.begin();
map<MovieBase::Movie,float>::iterator lit = topList.end();
lit--;
if(bit->second==lit->second||(weightedScore>bit->second)){
while(bit->second<weightedScore){
bit++;
}
topList.insert(bit,std::make_pair(thisMovie,weightedScore));
if(topList.size()>moviesToShow){
bit = topList.begin();
topList.erase(bit);
}
}
}
mit++;
}
map<MovieBase::Movie,float>::iterator finalPrintIterator = topList.begin();
cout << "User " << userID << "'s Top " << moviesToShow << " movies:" << endl;
while(finalPrintIterator!=topList.end()){
cout << finalPrintIterator->first.getName() << "(" << finalPrintIterator->first.getYear() << ") - Weighted Score: " << finalPrintIterator->second << endl;
finalPrintIterator++;
}
return topList;
}
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/s/Production/Projects/CSE250/250-REGAN-PROJ2/NetflixChallenge'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/netflixchallenge.exe
make[2]: Entering directory '/cygdrive/s/Production/Projects/CSE250/250-REGAN-PROJ2/NetflixChallenge'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f "build/Debug/Cygwin_4.x-Windows/UserBase.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/UserBase.o.d" -o build/Debug/Cygwin_4.x-Windows/UserBase.o UserBase.cpp
UserBase.cpp: In member function ‘std::map<MovieBase::Movie, float> UserBase::topMovieList(int, MovieBase*, unsigned int)’:
UserBase.cpp:146:51: error: passing ‘const MovieBase::Movie’ as ‘this’ argument of ‘std::string MovieBase::Movie::getName()’ discards qualifiers [-fpermissive]
cout << finalPrintIterator->first.getName() << "(" << finalPrintIterator->first.getYear() << ") - Weighted Score: " << finalPrintIterator->second << endl;
^
UserBase.cpp:146:97: error: passing ‘const MovieBase::Movie’ as ‘this’ argument of ‘unsigned int MovieBase::Movie::getYear()’ discards qualifiers [-fpermissive]
cout << finalPrintIterator->first.getName() << "(" << finalPrintIterator->first.getYear() << ") - Weighted Score: " << finalPrintIterator->second << endl;
^
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = MovieBase::Movie]’:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_tree.h:1422:8: required from ‘std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_hint_unique_pos(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator, const key_type&) [with _Key = MovieBase::Movie; _Val = std::pair<const MovieBase::Movie, float>; _KeyOfValue = std::_Select1st<std::pair<const MovieBase::Movie, float> >; _Compare = std::less<MovieBase::Movie>; _Alloc = std::allocator<std::pair<const MovieBase::Movie, float> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const MovieBase::Movie, float> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = MovieBase::Movie]’
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_tree.h:1478:64: required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique_(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator, const _Val&) [with _Key = MovieBase::Movie; _Val = std::pair<const MovieBase::Movie, float>; _KeyOfValue = std::_Select1st<std::pair<const MovieBase::Movie, float> >; _Compare = std::less<MovieBase::Movie>; _Alloc = std::allocator<std::pair<const MovieBase::Movie, float> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const MovieBase::Movie, float> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const MovieBase::Movie, float> >]’
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_map.h:648:54: required from ‘std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(std::map<_Key, _Tp, _Compare, _Alloc>::iterator, const value_type&) [with _Key = MovieBase::Movie; _Tp = float; _Compare = std::less<MovieBase::Movie>; _Alloc = std::allocator<std::pair<const MovieBase::Movie, float> >; std::map<_Key, _Tp, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const MovieBase::Movie, float> >; std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const MovieBase::Movie, float>]’
UserBase.cpp:124:71: required from here
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const MovieBase::Movie’ and ‘const MovieBase::Movie’)
{ return __x < __y; }
^
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: candidates are:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_algobase.h:64:0,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:40,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/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/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_pair.h:220:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::pair<_T1, _T2>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:40,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/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/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_iterator.h:297:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:40,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/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/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_iterator.h:347:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:52:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/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/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/basic_string.h:2569:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:52:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/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/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/basic_string.h:2581:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:52:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/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/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/basic_string.h:2593:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: mismatched types ‘const _CharT*’ and ‘MovieBase::Movie’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/map:60:0,
from UserBase.h:11,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_tree.h:917:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_tree.h:917:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/map:61:0,
from UserBase.h:11,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_map.h:979:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_map.h:979:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/map:62:0,
from UserBase.h:11,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_multimap.h:881:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_multimap.h:881:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/vector:64:0,
from MovieBase.h:11,
from UserBase.h:12,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_vector.h:1420:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_vector.h:1420:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/string:48:0,
from UserBase.h:10,
from UserBase.cpp:9:
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/include/c++/bits/stl_function.h:235:20: note: ‘const MovieBase::Movie’ is not derived from ‘const std::vector<_Tp, _Alloc>’
{ return __x < __y; }
^
nbproject/Makefile-Debug.mk:73: recipe for target 'build/Debug/Cygwin_4.x-Windows/UserBase.o' failed
make[2]: *** [build/Debug/Cygwin_4.x-Windows/UserBase.o] Error 1
make[2]: Leaving directory '/cygdrive/s/Production/Projects/CSE250/250-REGAN-PROJ2/NetflixChallenge'
nbproject/Makefile-Debug.mk:61: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/s/Production/Projects/CSE250/250-REGAN-PROJ2/NetflixChallenge'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
Not sure what the line 146 in userbase.cpp is, but you seem to call non-const member function on const object there.
The problem is that std::map<T> requires that the type T be equipped with an operator<() (either a 1-arg method or a 2-arg free function), but your MovieBase::Movie class doesn't provide one. std::map<T> needs this operator because it internally stores key-value pairs in a balanced binary tree, and this requires comparing different key values.
My guess is that
vector<MovieBase::Movie>::iterator
is the problem. The < it contains will probably be interpreted as a less-than sign if, for example, you haven't declared std::vector<T> by writing #include <vector> near the top of your code.
Here's the simple version. Below, I fully explain the real-world use case.
I've got two classes:
template<class T>
class Base {
protected:
virtual void foo();
std::map<std::string*, T*> things;
};
class Derived : public Base<int> {
protected:
void foo();
};
template<class T>
void Base<T>::foo() {
for (auto itr = things.begin(); itr < things.end(); ++itr) {
}
}
void Derived::foo() {
for (auto itr = things.begin(); itr < things.end(); ++itr) {
}
}
I run into problems with the for loop condition in the Derived implementation of foo:
example.cpp: In member function ‘virtual void Derived::foo()’:
example.cpp:23:53: error: no match for ‘operator<’ in ‘itr < ((Derived*)this)->Derived::<anonymous>.Base<int>::things.std::map<_Key, _Tp, _Compare, _Alloc>::end<std::basic_string<char>*, int*, std::less<std::basic_string<char>*>, std::allocator<std::pair<std::basic_string<char>* const, int*> > >()’
example.cpp:23:53: note: candidates are:
In file included from /usr/include/c++/4.7/string:54:0,
from example.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2590:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.7/bits/basic_string.h:2590:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: mismatched types ‘const _CharT*’ and ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’
In file included from /usr/include/c++/4.7/string:54:0,
from example.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2578:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.7/bits/basic_string.h:2578:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
In file included from /usr/include/c++/4.7/string:54:0,
from example.cpp:2:
/usr/include/c++/4.7/bits/basic_string.h:2566: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>&)
/usr/include/c++/4.7/bits/basic_string.h:2566:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
In file included from /usr/include/c++/4.7/map:62:0,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_multimap.h:822:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
/usr/include/c++/4.7/bits/stl_multimap.h:822:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
In file included from /usr/include/c++/4.7/map:61:0,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_map.h:906:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
/usr/include/c++/4.7/bits/stl_map.h:906:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
In file included from /usr/include/c++/4.7/map:60:0,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_tree.h:873:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
/usr/include/c++/4.7/bits/stl_tree.h:873:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:1063:5: note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
/usr/include/c++/4.7/bits/stl_iterator.h:1063:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::move_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:1057:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
/usr/include/c++/4.7/bits/stl_iterator.h:1057:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::move_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:349:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.7/bits/stl_iterator.h:349:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::reverse_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:299:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.7/bits/stl_iterator.h:299:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::reverse_iterator<_Iterator>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_pair.h:212:5: note: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/include/c++/4.7/bits/stl_pair.h:212:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const std::pair<_T1, _T2>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:838:5: note: template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
/usr/include/c++/4.7/bits/stl_iterator.h:838:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
In file included from /usr/include/c++/4.7/bits/stl_algobase.h:68:0,
from /usr/include/c++/4.7/bits/stl_tree.h:63,
from /usr/include/c++/4.7/map:60,
from example.cpp:1:
/usr/include/c++/4.7/bits/stl_iterator.h:832:5: note: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
/usr/include/c++/4.7/bits/stl_iterator.h:832:5: note: template argument deduction/substitution failed:
example.cpp:23:53: note: ‘std::_Rb_tree_iterator<std::pair<std::basic_string<char>* const, int*> >’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
Why doesn't this work, and what should I be doing to fix it?
P.S.: I know that this is a prime opportunity to use template specialization, but I don't think that is appropriate for my use case.
Here's the full story.
I'm making a scene graph with several types of nodes. Some of the important ones for this issue are:
SceneParent
SceneRegion
SceneGroup
SceneComponent
They each play the following roles:
SceneParent contains a set of children, of template type T.
SceneRegion extends SceneParent, specifying T as SceneParent
SceneGroup extends SceneParent, specifying T as SceneComponent
The function I am trying to implement is getVisibleChildren. Given a viewport, I want a receive a set of SceneComponents that should be rendered.
SceneParents implementation is recursively called on all children:
template< class T >
void SceneParent< T >::getVisibleChildren(const util::Camera& camera,
std::vector< SceneComponent* >& visibleChildren) const {
if (!this->isVisible(camera)) {
return;
}
// Get ids into a flat container so the next loop can be parallelized.
std::vector< std::string* > childIds;
for (auto itr = this->children.cbegin(); itr < this->children.cend();
++itr) {
childIds.push_back(itr->first);
}
// TODO: parallelize this.
for (auto itr = childIds.cbegin(); itr < childIds.cend(); ++itr) {
this->children[*itr]->getVisibleChildren(camera, visibleChildren);
}
}
SceneGroups implementation adds all of its SceneComponents to the accumulator (the assumption being that if a group is visible, so are its components). So the SceneGroup node acts as the base case for the recursion:
void SceneGroup::getVisibleChildren(const util::Camera& camera,
std::vector< SceneComponent* >& visibleChildren) const {
if (!this->isVisible(camera)) {
return;
}
// If this group is visible, assume all of its components are as well.
for (auto itr = this->children.cbegin(); itr < this->children.cend();
++itr) {
visibleChildren.push_back(itr->second);
}
}
Now that you have made it to this point in my post, I'm assuming you are interested (at least mildly) in my real-world application, not just the compiler error it is causing. So, if you feel so inclined, please offer any advice about how I can improve my implementation of the scene graph / things I should be looking out for while working on this project.
The iterators of std::map<K, V> are bidirectional iterators. It doesn't make any sense to use the less than operator for bidirectional iterator. Just write your loop using the equality or inequality operator:
for (auto itr = things.begin(); itr != things.end(); ++itr) {
}