Related
This question already has answers here:
Error using custom operator< with std::less
(2 answers)
Closed 4 years ago.
I want to define a static map inside a class, which will have a structure as both it's key and value. I've read that a '<' operator is needed to be defined, therefore I've included that definition inside the struct itself(I've randomly defined it as I don't need any comparison anywhere in my program).
The below sample code doesn't compile.The compiler produces a lot of warnings and errors which I don't understand right now. (Please ignore the uninitialized values in the main function):
#include<string>
#include<iostream>
#include<map>
using namespace std;
struct RJNodeAddress
{
string m_ip;
string m_port;
bool operator<(const RJNodeAddress &l)
{
int l_size=l.m_ip.size();
int r_size=l.m_port.size();
return (l_size < r_size);
}
};
struct RJNodeDetails
{
string m_NodeType;
int m_appId;
};
class RJWebsocket
{
public:
static map<RJNodeAddress,RJNodeDetails> m_Nodes;
};
int main()
{
RJNodeAddress l_node;
RJNodeDetails l_nodeDetails = RJWebsocket::m_Nodes[l_node];
}
Compiler output
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h: In instantiation of âconstexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = RJNodeAddress]â:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:491:32: required from âstd::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = RJNodeAddress; _Tp = RJNodeDetails; _Compare = std::less<RJNodeAddress>; _Alloc = std::allocator<std::pair<const RJNodeAddress, RJNodeDetails> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = RJNodeDetails; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = RJNodeAddress]â
test.cpp:34:59: required from here
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: error: no match for âoperator<â (operand types are âconst RJNodeAddressâ and âconst RJNodeAddressâ)
{ return __x < __y; }
~~~~^~~~~
test.cpp:10:14: note: candidate: bool RJNodeAddress::operator<(const RJNodeAddress&) <near match>
bool operator<(const RJNodeAddress &l)
^~~~~~~~
test.cpp:10:14: note: passing âconst RJNodeAddress*â as âthisâ argument discards qualifiers
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:64:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_pair.h:449:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_pair.h:449:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::pair<_T1, _T2>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:305:5: note: candidate: template<class _Iterator> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator<(const reverse_iterator<_Iterator>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:305:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::reverse_iterator<_Iterator>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:343:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator<(const reverse_iterator<_IteratorL>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:343:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::reverse_iterator<_Iterator>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1142:5: note: candidate: template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
operator<(const move_iterator<_IteratorL>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1142:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::move_iterator<_IteratorL>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_algobase.h:67:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/char_traits.h:39,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:40,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1148:5: note: candidate: template<class _Iterator> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
operator<(const move_iterator<_Iterator>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_iterator.h:1148:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::move_iterator<_IteratorL>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:485:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::basic_string_view<_CharT, _Traits>)
operator< (basic_string_view<_CharT, _Traits> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:485:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:491:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::__detail::__idt<std::basic_string_view<_CharT, _Traits> >)
operator< (basic_string_view<_CharT, _Traits> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:491:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:48:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:497:5: note: candidate: template<class _CharT, class _Traits> bool std::operator<(std::__detail::__idt<std::basic_string_view<_CharT, _Traits> >, std::basic_string_view<_CharT, _Traits>)
operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/string_view:497:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âRJNodeAddressâ is not derived from âstd::basic_string_view<_CharT, _Traits>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5892:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5892:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::basic_string<_CharT, _Traits, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5905:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5905:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::basic_string<_CharT, _Traits, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:52:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5917:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const _CharT* __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/basic_string.h:5917:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: mismatched types âconst _CharT*â and âRJNodeAddressâ
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/ios_base.h:46:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/ios:42,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/ostream:38,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/iostream:39,
from test.cpp:2:
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:208:3: note: candidate: bool std::operator<(const std::error_code&, const std::error_code&)
operator<(const error_code& __lhs, const error_code& __rhs) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:208:3: note: no known conversion for argument 1 from âconst RJNodeAddressâ to âconst std::error_code&â
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:282:3: note: candidate: bool std::operator<(const std::error_condition&, const std::error_condition&)
operator<(const error_condition& __lhs,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:282:3: note: no known conversion for argument 1 from âconst RJNodeAddressâ to âconst std::error_condition&â
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:808:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const std::optional<_Up>&)
operator<(const optional<_Tp>& __lhs, const optional<_Up>& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:808:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:861:5: note: candidate: template<class _Tp> constexpr bool std::operator<(const std::optional<_Tp>&, std::nullopt_t)
operator<(const optional<_Tp>& /* __lhs */, nullopt_t) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:861:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:866:5: note: candidate: template<class _Tp> constexpr bool std::operator<(std::nullopt_t, const std::optional<_Tp>&)
operator<(nullopt_t, const optional<_Tp>& __rhs) noexcept
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:866:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:926:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Tp>() < declval<_Up>()))> std::operator<(const std::optional<_Tp>&, const _Up&)
operator<(const optional<_Tp>& __lhs, const _Up& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:926:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:932:5: note: candidate: template<class _Tp, class _Up> constexpr std::__optional_relop_t<decltype ((declval<_Up>() < declval<_Tp>()))> std::operator<(const _Up&, const std::optional<_Tp>&)
operator<(const _Up& __lhs, const optional<_Tp>& __rhs)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/optional:932:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::optional<_Tp>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:39:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:40,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/array:262:5: note: candidate: template<class _Tp, long unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/array:262:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::array<_Tp, _Nm>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/node_handle.h:40:0,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:72,
from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:1410:5: note: candidate: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Tps ...>&, const std::tuple<_Elements ...>&)
operator<(const tuple<_TElements...>& __t,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/tuple:1410:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::tuple<_Tps ...>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:60:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:1543:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_tree.h:1543:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:61:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:1397:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_map.h:1397:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::map<_Key, _Tp, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/map:62:0,
from test.cpp:3:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_multimap.h:1062:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^~~~~~~~
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_multimap.h:1062:5: note: template argument deduction/substitution failed:
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/string:48:0,
from test.cpp:1:
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_function.h:386:20: note: âconst RJNodeAddressâ is not derived from âconst std::multimap<_Key, _Tp, _Compare, _Alloc>â
{ return __x < __y; }
~~~~^~~~~
As keys in std::map are const your operator< method must be const as well:
bool operator<(const RJNodeAddress &l) const
// ^ here
it should be const anyway as it does not modify the object but in this case missing it leads to compilation errors.
I am developing a limited version of shell for my self.
Here is a C++ program
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
using namespace std;
const int MAX = 256;
const int CMD_MAX = 10;
char *valid_cmds = " ls ps df ";
int main()
{
char line_input[MAX], the_cmd[CMD_MAX];
char *new_args[CMD_MAX], *cp;
int i;
while (1) {
cout << "cmd> ";
if (cin.getline(line_input, MAX, '\n') != NULL) {
cp = line_input;
i = 0;
if ((new_args[i] = strtok(cp, " ")) != NULL) {
strcpy(the_cmd, new_args[i]);
strcat(the_cmd, " ");
if ((strstr(valid_cmds, the_cmd) -valid_cmds)% 4 == 1) {
do {
cp = NULL;
new_args[++i] = strtok(cp, " ");
} while (i < CMD_MAX
&& new_args[i] != NULL);
new_args[i] = NULL;
switch (fork()) {
case 0:
execvp(new_args[0], new_args);
perror("exec failure");
exit(1);
case -1:
perror("fork failure");
exit(2);
default:
// In the parent we should be waiting for
// the child to finis h
;
}
} else
cout << "huh?" << endl;
}
}
}
}
What I am not able to understand is when I compile this program I am getting error in line
(cin.getline(line_input, MAX, '\n') != NULL)
and the error is following I do a
$ g++ p3.7.cpp
p3.7.cpp:10:20: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
char *valid_cmds = " ls ps df ";
^~~~~~~~~~~~
p3.7.cpp: In function ‘int main()’:
p3.7.cpp:18:42: error: no match for ‘operator!=’ (operand types are ‘std::basic_istream<char>’ and ‘long int’)
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
p3.7.cpp:18:42: note: candidate: operator!=(int, long int) <built-in>
p3.7.cpp:18:42: note: no known conversion for argument 1 from ‘std::basic_istream<char>’ to ‘int’
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iosfwd:40:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/postypes.h:221: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/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/postypes.h:221:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::fpos<_StateT>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algobase.h:64:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_pair.h:456: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/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_pair.h:456:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::pair<_T1, _T2>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:311: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/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:311:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:349: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/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:349:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:1130:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
operator!=(const move_iterator<_IteratorL>& __x,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:1130:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::move_iterator<_IteratorL>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:1136:5: note: candidate: template<class _Iterator> bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
operator!=(const move_iterator<_Iterator>& __x,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_iterator.h:1136:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::move_iterator<_IteratorL>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/string:41:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/allocator.h:158:5: note: candidate: template<class _T1, class _T2> bool std::operator!=(const std::allocator<_CharT>&, const std::allocator<_T2>&)
operator!=(const allocator<_T1>&, const allocator<_T2>&)
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/allocator.h:158:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::allocator<_CharT>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/string:41:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/allocator.h:164:5: note: candidate: template<class _Tp> bool std::operator!=(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/allocator.h:164:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::allocator<_CharT>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/string:52:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h:6044:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h:6044:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/string:52:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h:6057:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator!=(const _CharT* __lhs,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h:6057:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: mismatched types ‘const _CharT*’ and ‘std::basic_istream<char>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/string:52:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h:6069:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h:6069:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/ios_base.h:46:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:319:3: note: candidate: bool std::operator!=(const std::error_code&, const std::error_code&)
operator!=(const error_code& __lhs, const error_code& __rhs) noexcept
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:319:3: note: no known conversion for argument 1 from ‘std::basic_istream<char>’ to ‘const std::error_code&’
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:323:3: note: candidate: bool std::operator!=(const std::error_code&, const std::error_condition&)
operator!=(const error_code& __lhs, const error_condition& __rhs) noexcept
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:323:3: note: no known conversion for argument 1 from ‘std::basic_istream<char>’ to ‘const std::error_code&’
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:327:3: note: candidate: bool std::operator!=(const std::error_condition&, const std::error_code&)
operator!=(const error_condition& __lhs, const error_code& __rhs) noexcept
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:327:3: note: no known conversion for argument 1 from ‘std::basic_istream<char>’ to ‘const std::error_condition&’
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:331:3: note: candidate: bool std::operator!=(const std::error_condition&, const std::error_condition&)
operator!=(const error_condition& __lhs,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/system_error:331:3: note: no known conversion for argument 1 from ‘std::basic_istream<char>’ to ‘const std::error_condition&’
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/locale_facets.h:48:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_ios.h:37,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:44,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from p3.7.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/streambuf_iterator.h:210:5: note: candidate: template<class _CharT, class _Traits> bool std::operator!=(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
operator!=(const istreambuf_iterator<_CharT, _Traits>& __a,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/streambuf_iterator.h:210:5: note: template argument deduction/substitution failed:
In file included from /usr/include/sys/unistd.h:14:0,
from /usr/include/unistd.h:4,
from p3.7.cpp:6:
p3.7.cpp:18:45: note: ‘std::basic_istream<char>’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
if (cin.getline(line_input, MAX, '\n') != NULL) {
What is the mistake above I am doing. Do I need to include some header file which I have forgotten.
More of a style comment than anything. I'd be inclined to break up your main function into separate functions, each dealing with a different concern of the problem.
In this example I've used c++ data constructs rather than c-style ones.
I've also used boost::optional and boost::tokenizer.
The boost library suite is invaluable to any c++ developer as it provides many of the essential application programming tools that the c++ standard library fails to provide.
#include <boost/optional.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
using boost::optional;
using std::string;
using std::vector;
void prompt(std::istream& is)
{
if (std::addressof(is) == std::addressof(std::cin))
{
std::cout << "cmd> ";
}
}
optional<string> next_line(std::istream& is)
{
auto result = optional<string>();
std::string line;
while (1)
{
prompt(is);
if (!getline(is, line)) break;
if (!line.empty())
{
result = line;
break;
}
}
return result;
}
vector<string> tokenise(std::string const& source)
{
using char_function = boost::char_separator<char>;
auto tokens = boost::tokenizer<char_function>(source, char_function(" "));
return vector<string>(tokens.begin(), tokens.end());
}
auto to_char_data_vector(vector<string>::iterator first, vector<string>::iterator last) -> vector<char *>
{
auto to_char_data = [](std::string& str) { return str.data(); };
auto result = vector<char *>();
std::transform(first, last,
back_inserter(result),
to_char_data);
return result;
};
auto append_null(vector<char*> v) -> vector<char *>
{
v.push_back(nullptr);
return v;
}
int sub_command(string const& cmd, vector<string>& args) // note - not const.
{
auto do_error = [](const char *message)
{
auto retcode = errno;
std::cerr << message << std::endl;
return retcode;
};
auto pid = fork();
if (pid == -1)
{
return do_error("fork failure");
}
else if (pid == 0)
{
auto result = execv(cmd.data(),
append_null(to_char_data_vector(begin(args),
std::end(args)))
.data());
std::exit(do_error("execv failure"));
}
else
{
int stat = 0;
auto waitresult = waitpid(pid, &stat, 0);
if (waitresult == -1)
return do_error("failed to wait");
return WEXITSTATUS(stat);
}
}
/// #pre tokens.length() >= 1
int interpret(vector<string> const& tokens)
{
auto args = vector<string>(next(begin(tokens)), std::end(tokens));
auto& cmd = tokens[0];
if (boost::iequals(cmd, "exit"))
{
std::exit(args.empty() ? 0 : std::stoi(args[0]));
}
else
{
return sub_command(cmd, args);
}
}
int main()
{
while (auto opt_line = next_line(std::cin))
{
auto tokens = tokenise(*opt_line);
if (tokens.empty()) continue;
auto return_code = interpret(tokens);
std::cout << "command returned: " << return_code << std::endl;
}
}
example run:
cmd> /bin/ls .
CMakeCache.txt TryThings.cbp trythings
CMakeFiles _3rdParty
Makefile cmake_install.cmake
command returned: 0
cmd> exit 20
Process finished with exit code 20
Note that I had to specify the exact path of the ls command. evecv knows nothing about search paths.
I have been trying to implement a Priority queue consisting of a custom data type and a custom comparator but when I try to compile I get this error. I have tried multiple declarations but they all yield this error.
priority_queue<myData, vector<myData>, myComp> myPQ;
priority_queue<myData, vector<myData>, myComp> myPQ(compVariable);
I also am trying to create a vector of these priority queues after creating them.
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Order]’:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_heap.h:183:47: required from ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Order*, std::vector<Order, std::allocator<Order> > >; _Distance = long int; _Tp = Order; _Compare = std::less<Order>]’
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_heap.h:222:58: required from ‘void std::push_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Order*, std::vector<Order, std::allocator<Order> > >; _Compare = std::less<Order>]’
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_queue.h:499:41: required from ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = Order; _Sequence = std::vector<Order, std::allocator<Order> >; _Compare = std::less<Order>; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = Order]’
Market.cpp:144:32: required from here
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const Order’ and ‘const Order’)
{ return __x < __y; }
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: candidates are:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_pair.h:220:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::pair<_T1, _T2>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:297:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:347:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:1055:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:1061:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:52:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2569:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:52:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2581:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:52:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2593:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: mismatched types ‘const _CharT*’ and ‘Order’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/vector:64:0,
from P2.h:4,
from Market.cpp:3:
/usr/um/gcc-4.8.2/include/c++/4.8.2/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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_vector.h:1420:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::vector<_Tp, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/deque:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:60,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:273:5: note: 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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:273:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/deque:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:60,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:281:5: note: 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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:281:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/deque:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:60,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:1975:5: note: 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/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:1975:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::deque<_Tp, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:64:0,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_queue.h:286:5: note: template<class _Tp, class _Seq> bool std::operator<(const std::queue<_Tp, _Seq>&, const std::queue<_Tp, _Seq>&)
operator<(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y)
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_queue.h:286:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::queue<_Tp, _Seq>’
{ return __x < __y; }
Here is an example of what is causing the error:
class myData {
public:
int a;
int b;
int c;
int d;
};
class myComp {
public:
bool operator()(myData& d1, myData& d2) {
if(d1.a == d2.a) {
return d2.b < d2.c;
}
else {
return d1.a < d2.a;
}
}
};
priority_queue<myData, vector<myData>, myComp> myPQ;
vector<priority_queue<myData, vector<myData>, myComp> > vec_PQ(n, myPQ);
From : http://en.cppreference.com/w/cpp/concept/Compare
The concept Compare is a set of requirements expected by some of the standard library facilities from the user-provided function object types.
The return value of the function call operation applied to an object of type Compare, when contextually converted to bool, yields true if the first argument of the call appears before the second in the strict weak ordering relation induced by this Compare type, and false otherwise.
As with any BinaryPredicate, evaluation of that expression is not allowed to call non-const member functions of the dereferenced iterators.
The arguments to myComp::operator() should be const&.
bool myComp::operator()(myData const& d1, myData const& d2) {
As indicated by #T.C. in a comment, the function itself should be a const member function but that is strictly not necessary in this case.
I'm currently working on a project involving hash tables. I've read in a text file into a vector of Symbol structs and I now have to insert these structs (objects, really) into a hash table. I was given a specific insertion function to use, however, I can't seem to get it to work. I've included the insertion function below as well as my Driver.cpp file which contains reading in the file to vector of structs and my attempt at inserting this into the hash table.
I would appreciate any help/feedback has to where I'm going wrong.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <string>
#include <time.h>
#include <unistd.h>
#include "SeparateChaining.h"
using namespace std;
struct Symbol
{
int type;
string name;
};
size_t hash(const string & key); //declaration of hashing function
int main()
{
/************ VARS ***************/
string line;
int line_count;
int table_size;
int increment;
/************ Vector of Symbols ***************/
vector<Symbol> symbols;
/************ HashTable of Symbols ***************/
HashTable<Symbol> hashtable; //precomputed to have 101 elements --> probably will change this to accomodate table size.
cout << "Opening file..." << endl;
usleep(2000000);
ifstream file;
file.open("symbols.txt");
if(!file)
{
cout << "System failed to open file.";
}
else
{
cout << "File successfully opened" << endl;
}
cout << "Please enter the table size for the Hash Table. (NOTE: It MUST be a prime number.)" << endl;
cin >> table_size;
for(Symbol temp; file >> temp.name >> temp.type;)
{
symbols.push_back(temp);
increment++;
}
//Just to test and see if its loading it correctly...
for(int i = 0; i < symbols.size(); i++)
{
cout << symbols[i].name << endl;
cout << symbols[i].type << endl;
}
for(int j = 0; j < symbols.size(); j++)
{
hashtable.insert(symbols); // Messing up here !!!!!!!!!!!!!
}
//cout << ::hash("hi") << endl;
}
size_t hash( const string & key )
{
size_t hashVal = 0;
for( char ch : key )
hashVal = 37 * hashVal + ch;
return hashVal;
}
Insert function(s) in the SeparateChaining.h:
bool insert( const HashedObj & x )
{
auto & whichList = theLists[ myhash( x ) ];
if( find( begin( whichList ), end( whichList ), x ) != end( whichList) )
return false;
whichList.push_back( x );
// Rehash; see Section 5.5
if( ++currentSize > theLists.size( ) )
rehash( );
return true;
}
bool insert( HashedObj && x )
{
auto & whichList = theLists[ myhash( x ) ];
if( find( begin( whichList ), end( whichList ), x ) != end( whichList ) )
return false;
whichList.push_back( std::move( x ) );
// Rehash; see Section 5.5
if( ++currentSize > theLists.size( ) )
rehash( );
return true;
}
Errors when done as hashtable.insert(symbols):
Driver.cpp: In function 'int main()':
Driver.cpp:65:27: error: no matching function for call to 'HashTable<Symbol>::insert(std::vector<Symbol>&)'
Driver.cpp:65:27: note: candidates are:
In file included from Driver.cpp:8:0:
SeparateChaining.h:44:10: note: bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]
SeparateChaining.h:44:10: note: no known conversion for argument 1 from 'std::vector<Symbol>' to 'const Symbol&'
SeparateChaining.h:58:10: note: bool HashTable<HashedObj>::insert(HashedObj&&) [with HashedObj = Symbol]
SeparateChaining.h:58:10: note: no known conversion for argument 1 from 'std::vector<Symbol>' to 'Symbol&&'
Errors when done as hashtable.insert(symbols[j]) after incrementing through the vector:
In file included from /opt/local/include/gcc47/c++/bits/basic_string.h:3032:0,
from /opt/local/include/gcc47/c++/string:54,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/functional_hash.h: In instantiation of 'struct std::hash<Symbol>':
SeparateChaining.h:107:32: required from 'size_t HashTable<HashedObj>::myhash(const HashedObj&) const [with HashedObj = Symbol; size_t = long unsigned int]'
SeparateChaining.h:46:50: required from 'bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]'
Driver.cpp:65:30: required from here
/opt/local/include/gcc47/c++/bits/functional_hash.h:60:7: error: static assertion failed: std::hash is not specialized for this type
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h: In instantiation of '_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&, std::input_iterator_tag) [with _InputIterator = std::_List_iterator<Symbol>; _Tp = Symbol]':
/opt/local/include/gcc47/c++/bits/stl_algo.h:4466:45: required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = std::_List_iterator<Symbol>; _Tp = Symbol]'
SeparateChaining.h:47:9: required from 'bool HashTable<HashedObj>::insert(const HashedObj&) [with HashedObj = Symbol]'
Driver.cpp:65:30: required from here
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: error: no match for 'operator==' in '__first.std::_List_iterator<_Tp>::operator*<Symbol>() == __val'
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: candidates are:
In file included from /opt/local/include/gcc47/c++/bits/stl_algo.h:68:0,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/functional:2382:5: note: template<class _Res, class ... _Args> bool std::operator==(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)
/opt/local/include/gcc47/c++/functional:2382:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: cannot convert '__first.std::_List_iterator<_Tp>::operator*<Symbol>()' (type 'Symbol') to type 'std::nullptr_t'
In file included from /opt/local/include/gcc47/c++/bits/stl_algo.h:68:0,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/functional:2376:5: note: template<class _Res, class ... _Args> bool std::operator==(const std::function<_Res(_ArgTypes ...)>&, std::nullptr_t)
/opt/local/include/gcc47/c++/functional:2376:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::function<_Res(_ArgTypes ...)>'
In file included from /opt/local/include/gcc47/c++/functional:56:0,
from /opt/local/include/gcc47/c++/bits/stl_algo.h:68,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/tuple:797:5: note: template<class ... _TElements, class ... _UElements> bool std::operator==(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
/opt/local/include/gcc47/c++/tuple:797:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::tuple<_Elements ...>'
In file included from /opt/local/include/gcc47/c++/random:51:0,
from /opt/local/include/gcc47/c++/bits/stl_algo.h:67,
from /opt/local/include/gcc47/c++/algorithm:63,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/random.tcc:1713:5: note: template<class _RealType1> bool std::operator==(const std::normal_distribution<_RealType>&, const std::normal_distribution<_RealType>&)
/opt/local/include/gcc47/c++/bits/random.tcc:1713:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::normal_distribution<_RealType>'
In file included from /opt/local/include/gcc47/c++/list:64:0,
from SeparateChaining.h:6,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_list.h:1574:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)
/opt/local/include/gcc47/c++/bits/stl_list.h:1574:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::list<_Tp, _Alloc>'
In file included from /opt/local/include/gcc47/c++/list:64:0,
from SeparateChaining.h:6,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_list.h:277:5: note: template<class _Val> bool std::operator==(const std::_List_iterator<_Tp>&, const std::_List_const_iterator<_Val>&)
/opt/local/include/gcc47/c++/bits/stl_list.h:277:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::_List_iterator<_Tp>'
In file included from /opt/local/include/gcc47/c++/vector:65:0,
from Driver.cpp:4:
/opt/local/include/gcc47/c++/bits/stl_vector.h:1370:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
/opt/local/include/gcc47/c++/bits/stl_vector.h:1370:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::vector<_Tp, _Alloc>'
In file included from /opt/local/include/gcc47/c++/bits/locale_facets.h:50:0,
from /opt/local/include/gcc47/c++/bits/basic_ios.h:39,
from /opt/local/include/gcc47/c++/ios:45,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/streambuf_iterator.h:206:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
/opt/local/include/gcc47/c++/bits/streambuf_iterator.h:206:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::istreambuf_iterator<_CharT, _Traits>'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2516:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/opt/local/include/gcc47/c++/bits/basic_string.h:2516:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2504:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/opt/local/include/gcc47/c++/bits/basic_string.h:2504:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: mismatched types 'const _CharT*' and 'Symbol'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2490: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>&)
/opt/local/include/gcc47/c++/bits/basic_string.h:2490:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::basic_string<_CharT>'
In file included from /opt/local/include/gcc47/c++/string:54:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/basic_string.h:2483: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>&)
/opt/local/include/gcc47/c++/bits/basic_string.h:2483:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
In file included from /opt/local/include/gcc47/c++/string:43:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/allocator.h:124:5: note: template<class _Tp> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
/opt/local/include/gcc47/c++/bits/allocator.h:124:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::allocator<_CharT>'
In file included from /opt/local/include/gcc47/c++/string:43:0,
from /opt/local/include/gcc47/c++/bits/locale_classes.h:42,
from /opt/local/include/gcc47/c++/bits/ios_base.h:43,
from /opt/local/include/gcc47/c++/ios:43,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/allocator.h:119:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
/opt/local/include/gcc47/c++/bits/allocator.h:119:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::allocator<_CharT>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1039:5: note: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1039:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::move_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1033:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:1033:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::move_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:343:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:343:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::reverse_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:68:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_iterator.h:293:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/opt/local/include/gcc47/c++/bits/stl_iterator.h:293:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::reverse_iterator<_Iterator>'
In file included from /opt/local/include/gcc47/c++/bits/stl_algobase.h:65:0,
from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
from /opt/local/include/gcc47/c++/ios:41,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/stl_pair.h:206:5: note: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/opt/local/include/gcc47/c++/bits/stl_pair.h:206:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::pair<_T1, _T2>'
In file included from /opt/local/include/gcc47/c++/iosfwd:42:0,
from /opt/local/include/gcc47/c++/ios:39,
from /opt/local/include/gcc47/c++/ostream:40,
from /opt/local/include/gcc47/c++/iostream:40,
from Driver.cpp:1:
/opt/local/include/gcc47/c++/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
/opt/local/include/gcc47/c++/bits/postypes.h:218:5: note: template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/algorithm:63:0,
from SeparateChaining.h:8,
from Driver.cpp:8:
/opt/local/include/gcc47/c++/bits/stl_algo.h:135:7: note: 'Symbol' is not derived from 'const std::fpos<_StateT>'
Try
hashtable.insert(symbols[j]);
Also, you don't use increment, line_count or table_size, you just set them.
Explanation:
You're trying to insert the whole vector, not its elements, hence the datatype mismatch. By using array notation, you grab the actual element you want to insert.
Why do you even use the vector instead of inserting your symbols directly into the hash table?
temp_holder.clear();
temp_holder << n;
n_str = temp_holder.str();
int f = count(n_str.begin(), n_str.end(), a);
That's my code, and this is g++ output:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h: In instantiation of ‘typename std::iterator_traits<_InputIterator>::difference_type std::count(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _Tp = std::basic_string<char>; typename std::iterator_traits<_InputIterator>::difference_type = long int]’:
trintatres.cpp:44:50: required from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: error: no match for ‘operator==’ in ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<char*, std::basic_string<char> >() == __value’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: candidates are:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iosfwd:42:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:39,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/postypes.h:218:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/postypes.h:218:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::fpos<_StateT>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:65:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:212:5: note: template<class _T1, class _T2> bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:212:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::pair<_T1, _T2>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:293:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:293:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::reverse_iterator<_Iterator>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:343:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:343:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::reverse_iterator<_IteratorL>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:43:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:119:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_T1>&, const std::allocator<_T2>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:119:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::allocator<_T1>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:43:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:124:5: note: template<class _Tp> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:124:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::allocator<_Tp1>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2483: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/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2483:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2490: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>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2490:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::basic_string<_CharT>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2504:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2504:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const _CharT*’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:54:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2516:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_string.h:2516:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_facets.h:50:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/basic_ios.h:39,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:45,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/streambuf_iterator.h:206:5: note: template<class _CharT, class _Traits> bool std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/streambuf_iterator.h:206:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const std::istreambuf_iterator<_CharT, _Traits>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/x86_64-unknown-linux-gnu/bits/c++allocator.h:34:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/allocator.h:48,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/string:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:43,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ext/new_allocator.h:129:5: note: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ext/new_allocator.h:129:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const __gnu_cxx::new_allocator<_Tp>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:813: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/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:813:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’ and ‘char’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:68:0,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:41,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:40,
from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:40,
from trintatres.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:807: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/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_iterator.h:807:5: note: template argument deduction/substitution failed:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algo.h:4656:2: note: mismatched types ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’ and ‘char’
I honestly think I'm using std::count from correctly, according to cplusplus.com.
Any idea of what I'm doing wrong?
EDIT
Full code:
#include <iostream>
#include <string>
#include <sstream>
#include <climits>
#include <algorithm>
using namespace std;
int max(int a, int b) {
return (a > b) ? a : b;
}
int main() {
string a;
cin >> a;
int c;
cin >> c;
int q;
cin >> q;
string cases[q];
int max_case = INT_MIN;
int temp;
for (int i = 0; i < q; i++) {
cin >> temp;
max_case = max(temp, max_case);
stringstream current_case_holder;
current_case_holder << temp;
cases[i] = current_case_holder.str();
}
int sequence[max_case];
int n;
stringstream temp_holder;
string n_str;
for (int i = 0; i < max_case; i++) {
n = 1;
while (true) {
temp_holder.clear();
temp_holder << n;
n_str = temp_holder.str();
int f = count(n_str.begin(), n_str.end(), a);
//}
n++;
}
}
return 0;
}
The first error tells you all you need to know:
In instantiation of ‘typename std::iterator_traits<_InputIterator>::difference_type std::count(_IIter, _IIter, const _Tp&)
[with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >;
_Tp = std::basic_string<char>;
typename std::iterator_traits<_InputIterator>::difference_type = long int]’
This indicates that you're passing a std::string object for the third argument to std::count, which is wrong; you need to pass a char object instead, since you're effectively iterating over a std::string, and std::string::value_type is char.