Unable to insert smart pointer into map - c++

I am trying to insert my smart pointer, p_pointer<foo> pointing towards a foo class into map, however the program would not compile. Therefore I tried to use a normal pointer foo* and the program does compile. So far, I have been able to use the p_pointer like a normal pointer without any issue so I am surprised that this does not work. If anyone can explain to me why this would not work...
#include <iostream>
#include<map>
#include<string>
using namespace std;
template <class T>
class p_pointer
{
public:
T* cp;
size_t* refptr;
size_t* counter()
{
return refptr;
}
//default constructor
p_pointer():cp(0),refptr(new size_t(1)) {}
p_pointer(T*t):cp(t),refptr(new size_t(1)) {}
//copy constructor
p_pointer (const p_pointer&s):cp(s.cp),refptr(s.refptr)
{
refptr=s.refptr;
cp=s.cp;
*refptr=*refptr+1;
}
//destructor
~p_pointer()
{
if(--*refptr==0)
{
delete cp;
delete refptr;
}
}
//assignment operator
p_pointer&operator=(const p_pointer&s)
{
++*s.refptr;
//freeing the left hand size if it is the last one
if(--*refptr==0)
{
delete cp;
delete refptr;
}
cp=s.cp;
refptr=s.refptr;
}
operator bool()
{
return cp;
}
T*&operator->()
{
if(cp)
return cp;
else throw std::runtime_error("uninitialized player");
}
T operator*()
{
if(cp)
return *cp;
else throw std::runtime_error("uninitialized player");
}
};
class foo
{};
Method 1 (works)
int main()
{
map<foo*,int> x;
foo* y=new foo();
x[y]=1;
}
Method 2 (does not work)
int main()
{
map<p_pointer<foo>,int> x;
p_pointer<foo> y=new foo();
x[y]=1;
}
The error message is:
This is my first time posting an error message. I just copied all the content from build messages and paste it into here. Please let me know if this is not the optimal way
||=== Build: Debug in trial 821 (compiler: GNU GCC Compiler) ===|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h||In instantiation of 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = p_pointer<foo>]':|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_map.h|498|required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = p_pointer<foo>; _Tp = int; _Compare = std::less<p_pointer<foo> >; _Alloc = std::allocator<std::pair<const p_pointer<foo>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = p_pointer<foo>]'|
C:\trial 821\main.cpp|80|required from here|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|error: no match for 'operator<' (operand types are 'const p_pointer<foo>' and 'const p_pointer<foo>')|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: candidates are:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: operator<(int, int) <built-in>|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: no known conversion for argument 2 from 'const p_pointer<foo>' to 'int'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_pair.h|220|note: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_pair.h|220|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::pair<_T1, _T2>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|298|note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|298|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::reverse_iterator<_Iterator>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|348|note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|348|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::reverse_iterator<_Iterator>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|1072|note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|1072|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::move_iterator<_Iterator>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|1078|note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_iterator.h|1078|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::move_iterator<_Iterator>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\basic_string.h|2588|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>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\basic_string.h|2588|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\basic_string.h|2600|note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\basic_string.h|2600|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\basic_string.h|2612|note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\basic_string.h|2612|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: mismatched types 'const _CharT*' and 'p_pointer<foo>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_tree.h|980|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>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_tree.h|980|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\array|242|note: template<class _Tp, unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\array|242|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::array<_Tp, _Nm>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\tuple|857|note: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Args1 ...>&, const std::tuple<_Args2 ...>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\tuple|857|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::tuple<_Args1 ...>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_map.h|1017|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>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_map.h|1017|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::map<_Key, _Tp, _Compare, _Alloc>'|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_multimap.h|920|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>&)|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_multimap.h|920|note: template argument deduction/substitution failed:|
C:\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\stl_function.h|371|note: 'const p_pointer<foo>' is not derived from 'const std::multimap<_Key, _Tp, _Compare, _Alloc>'|
||=== Build failed: 1 error(s), 3 warning(s) (0 minute(s), 0 second(s)) ===|

Your problem can be found in the error message: no match for 'operator<' (operand types are 'const p_pointer' and 'const p_pointer')|. In order to use map with a custom type (p_pointer in this case), that type needs to declare a comparison operator < which is used to sort the keys in the map. You'll need to implement the < operator, and that should fix this error. (Other errors may show up to replace it though.)
Again, I would recommend just using the existing std::shared_ptr rather than re-implementing it yourself, unless you have some reason not to do so.

Related

g++ ultra verbosity nightmare

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.

c++ map creation and allocation in a class member

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.

C++ (NetBeans) stating I'm using an operator that appears nowhere in my code?

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.

C++: overriding function from templated base class

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) {
}

using the find function from algorithm on vector

I want to use the find function from the algorithm library on a vector object. The vector object is a vector of customers, (Customer is a class I made). I first ran it and it gave me an error in stl_algo.h. I search the web for it and I searched here for it too, I found a question here about it and I ran the same code, but I still got that error.
My code is here:
Header File:
#include <string>
#include <sstream>
#include <map>
#include <vector>
using namespace std;
enum Status {ACTIVE, INACTIVE};
class Customer {
private:
// ID Database class for storing customers' ids
class IdDB {
private:
friend class Customer;
// member field
static map <string, int> idList;
// member function
static int getNumber (const string &threeLetters) {
map<string, int>::iterator i = idList.find(threeLetters);
if (i == idList.end()) {
idList.insert(pair <string, int> (threeLetters, 0));
return 0;
}else{
return ++(i->second);
}
}
};
string id;
string name;
string address;
Status status;
void makeId () {
string threeLetters = name.substr(0, 3);
int idNum = IdDB::getNumber(threeLetters);
stringstream oss;
oss << threeLetters << idNum;
id = oss.str();
}
public:
Customer (const string&, const string&, const Status);
// Accessor Methods
string &getId ();
string &getName ();
string &getAddress ();
Status getStatus ();
// Mutator Methods
void setAddress (const string&);
void setStatus (const Status);
// Misc. Methods
void printStatus ();
// Equality Operator Overloading
friend bool operator == (Customer&, Customer&);
};
class CustomerDB {
private:
static vector<Customer> customersList;
public:
static void addCustomer (const Customer&);
static void deleteCustomer (Customer&);
};
Source Code:
#include <iostream>
#include <string>
#include <algorithm>
#include "Customer.h"
using namespace std;
map<string, int> Customer::IdDB::idList;
Customer::Customer (const string &cName, const string &cAddress, const Status cStatus) : name(cName), address(cAddress), status(cStatus) {
makeId();
}
// Accessor Methods
string &Customer::getId () { return id; }
string &Customer::getName () { return name; }
string &Customer::getAddress () { return address; }
Status Customer::getStatus () { return status; }
// Mutator Methods
void Customer::setAddress (const string &newAddress) { address = newAddress; }
void Customer::setStatus (const Status newStatus) { status = newStatus; }
// Misc. Methods
void Customer::printStatus () {
if (status == ACTIVE)
cout << "Active";
else
cout << "In-Active";
}
vector<Customer> CustomerDB::customersList;
void CustomerDB::addCustomer (const Customer &customer) {
customersList.push_back(customer);
}
void CustomerDB::deleteCustomer (Customer &customer) {
vector<Customer>::iterator i;
i = find(customersList.begin(), customersList.end(), customer); // getting error in here
}
// Equality Operator Overloading
bool operator == (Customer &cust1, Customer &cust2) {
return cust1.getId() == cust2.getId();
}
after building with Code::Blocks, I got this,
in header file stl_algo.h:
}
/// This is an overload used by find() for the RAI case.
template<typename _RandomAccessIterator, typename _Tp>
_RandomAccessIterator
__find(_RandomAccessIterator __first, _RandomAccessIterator __last,
const _Tp& __val, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::difference_type
__trip_count = (__last - __first) >> 2;
for (; __trip_count > 0; --__trip_count)
{
if (*__first == __val) // error in here exactly getting a red block
return __first;
++__first;
if (*__first == __val)
return __first;
++__first;
if (*__first == __val)
return __first;
Thanks
EDIT: Here is the build log
Compiling: C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/algorithm:63:0,
from C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:5:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h: In function '_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Customer*, std::vector<Customer> >, _Tp = Customer]':
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:4403:45: instantiated from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<Customer*, std::vector<Customer> >, _Tp = Customer]'
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:42:66: instantiated from here
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:162:4: error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Customer*, _Container = std::vector<Customer>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Customer&]() == __val'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:162:4: note: candidates are:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_pair.h:201:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:285:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:335:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:122:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:127:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2427: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2434:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2448:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2460:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/streambuf_iterator.h:194:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:309:5: note: template<class _Val> bool std::operator==(const std::_Rb_tree_iterator<_Tp>&, const std::_Rb_tree_const_iterator<_Val>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:846: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_map.h:877: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_multimap.h:795: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_vector.h:1273:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: bool operator==(Customer&, Customer&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: no known conversion for argument 2 from 'const Customer' to 'Customer&'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:4403:45: instantiated from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<Customer*, std::vector<Customer> >, _Tp = Customer]'
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:42:66: instantiated from here
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:166:4: error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Customer*, _Container = std::vector<Customer>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Customer&]() == __val'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:166:4: note: candidates are:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_pair.h:201:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:285:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:335:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:122:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:127:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2427: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2434:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2448:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2460:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/streambuf_iterator.h:194:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:309:5: note: template<class _Val> bool std::operator==(const std::_Rb_tree_iterator<_Tp>&, const std::_Rb_tree_const_iterator<_Val>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_tree.h:846: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_map.h:877: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_multimap.h:795: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_vector.h:1273:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: bool operator==(Customer&, Customer&)
C:\Users\KiKo-SaMa\Desktop\C++\DVD_App\Customer.cpp:46:6: note: no known conversion for argument 2 from 'const Customer' to 'Customer&'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:170:4: error: no match for 'operator==' in '__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Customer*, _Container = std::vector<Customer>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Customer&]() == __val'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_algo.h:170:4: note: candidates are:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_pair.h:201:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:285:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/stl_iterator.h:335:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:122:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/allocator.h:127:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2427: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>&)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.h:2434:5: note: template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const std::basic_string<_CharT>&, const std::basic_string<_CharT>&)
Process terminated with status 1 (0 minutes, 1 seconds)
50 errors, 0 warnings
You should work on your const correctness, the problem is that your equality comparator takes the arguments by non const reference, but the last argument to find is taken by const reference, which means that the compiler cannot use it there.
Incidentally, once you add the const there you will be forced to add const accessors to the data. Also, if your operator only uses the public interface there is no need to declare it as a friend
CodeBlocks may give errors about the stl files however they are not actually the errors. It shows the related stl file of your error.