I'm trying to implement a custom doubly linked list which works with std::find and other algorithms, I made a iterator for it which works with for loop however it does not work and is giving me a lot of errors, where do you think my problem is?
here is my simplified code:
template<typename T, class Allocator = std::allocator<T>>
class MyList {
private:
class Link {
public:
T item;
std::shared_ptr<Link> next; // next item
std::shared_ptr<Link> prev; // previous item
};
std::shared_ptr<Link> head;
std::shared_ptr<Link> tail;
public:
using allocator_type = Allocator;
using reference_link = T &;
class iterator {
public:
typedef iterator self_type;
typedef Link value_type;
typedef Link &reference;
typedef std::shared_ptr<Link> pointer;
typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
iterator(pointer ptr) : _link(ptr) { }
self_type operator++() {
std::shared_ptr<Link> temp{new Link};
if (_link->next) {
temp->item = _link->next->item;
temp->next = _link->next->next;
temp->prev = _link->next->prev;
}
else {
temp->next = nullptr;
temp->prev = _link->prev->next;
}
this->_link = temp;
return *this;
}
self_type operator++(int junk) {
std::shared_ptr<Link> temp{new Link};
if (_link->next) {
temp->item = _link->next->item;
temp->next = _link->next->next;
temp->prev = _link->next->prev;
}
else {
temp->next = nullptr;
temp->prev = _link->prev->next;
}
this->_link = temp;
return *this;
}
reference operator*() { return *_link; }
pointer operator->() { return _link; }
bool operator==(const self_type &l) const {
if (_link->next == l._link->next && _link->prev == l._link->prev && _link->item == l._link->item) {
return true;
}
return false;
}
bool operator!=(const self_type &l) const {
return !operator==(l);
}
friend bool operator==(const iterator &lhs, const T &rhs) {
if (lhs->item == rhs) {
return true;
}
return false;
};
private:
pointer _link;
};
iterator begin();
iterator end();
using iterator = iterator;
using const_iterator = const iterator;
};
template<typename T, class Allocator>
typename MyList<T, Allocator>::iterator MyList<T, Allocator>::begin() {
return iterator{tail};
}
template<typename T, class Allocator>
typename MyList<T, Allocator>::iterator MyList<T, Allocator>::end() {
return (iterator{head})++;
}
This one works fine:
MyList<int, std::allocator<int>> m_list{1, 2, 3,};
for (MyList<int, std::allocator<int>>::iterator i = m_list.begin();
i != m_list.end(); ++i) {
std::cout << i->item;
}
but this gives me many error:
auto result1 = std::find(m_list.begin(), m_list.end(), 3 );
Which some are these:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&, std::input_iterator_tag) [with _InputIterator = MyList<int, std::allocator<int> >::iterator; _Tp = int]’:
/usr/include/c++/4.8/bits/stl_algo.h:4441:45: required from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = MyList<int, std::allocator<int> >::iterator; _Tp = int]’
/home/epezhman/cpp/Part1/assignment4/src/main.cpp:44:63: required from here
/usr/include/c++/4.8/bits/stl_algo.h:139:46: error: no match for ‘operator==’ (operand types are ‘MyList<int, std::allocator<int> >::Link’ and ‘const int’)
while (__first != __last && !(*__first == __val))
^
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: candidates are:
In file included from /usr/include/c++/4.8/random:52:0,
from /usr/include/c++/4.8/bits/stl_algo.h:65,
from /usr/include/c++/4.8/algorithm:62,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/random.tcc:2030:5: note: template<class _RealType1> bool std::operator==(const std::normal_distribution<_RealType>&, const std::normal_distribution<_RealType>&)
operator==(const std::normal_distribution<_RealType>& __d1,
^
/usr/include/c++/4.8/bits/random.tcc:2030:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::normal_distribution<_RealType>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/vector:64:0,
from /usr/include/c++/4.8/bits/random.h:34,
from /usr/include/c++/4.8/random:50,
from /usr/include/c++/4.8/bits/stl_algo.h:65,
from /usr/include/c++/4.8/algorithm:62,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_vector.h:1404:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/4.8/bits/stl_vector.h:1404:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::vector<_Tp, _Alloc>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/iterator:66:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:4,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stream_iterator.h:130:5: note: template<class _Tp, class _CharT, class _Traits, class _Dist> bool std::operator==(const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>&, const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>&)
operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
^
/usr/include/c++/4.8/bits/stream_iterator.h:130:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::istream_iterator<_Tp, _CharT, _Traits, _Dist>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/locale_facets.h:48:0,
from /usr/include/c++/4.8/bits/basic_ios.h:37,
from /usr/include/c++/4.8/ios:44,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:2,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: 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/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:82:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr.h:338:5: note: template<class _Tp> bool std::operator==(std::nullptr_t, const std::shared_ptr<_Tp1>&)
operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
^
/usr/include/c++/4.8/bits/shared_ptr.h:338:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:82:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr.h:333:5: note: template<class _Tp> bool std::operator==(const std::shared_ptr<_Tp1>&, std::nullptr_t)
operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
^
/usr/include/c++/4.8/bits/shared_ptr.h:333:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::shared_ptr<_Tp1>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:82:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr.h:327:5: note: template<class _Tp1, class _Tp2> bool std::operator==(const std::shared_ptr<_Tp1>&, const std::shared_ptr<_Tp2>&)
operator==(const shared_ptr<_Tp1>& __a,
^
/usr/include/c++/4.8/bits/shared_ptr.h:327:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::shared_ptr<_Tp1>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:1040:5: note: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(std::nullptr_t, const std::__shared_ptr<_Tp, _Lp>&)
operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
^
/usr/include/c++/4.8/bits/shared_ptr_base.h:1040:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:1035:5: note: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp, _Lp>&, std::nullptr_t)
operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
^
/usr/include/c++/4.8/bits/shared_ptr_base.h:1035:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::__shared_ptr<_Tp, _Lp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/bits/shared_ptr.h:52:0,
from /usr/include/c++/4.8/memory:82,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/shared_ptr_base.h:1029:5: note: template<class _Tp1, class _Tp2, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp1, _Lp>&, const std::__shared_ptr<_Tp2, _Lp>&)
operator==(const __shared_ptr<_Tp1, _Lp>& __a,
^
/usr/include/c++/4.8/bits/shared_ptr_base.h:1029:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::__shared_ptr<_Tp1, _Lp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:81:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:500:5: note: template<class _Tp, class _Dp> bool std::operator==(std::nullptr_t, const std::unique_ptr<_Tp, _Dp>&)
operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
^
/usr/include/c++/4.8/bits/unique_ptr.h:500:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:81:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:495:5: note: template<class _Tp, class _Dp> bool std::operator==(const std::unique_ptr<_Tp, _Dp>&, std::nullptr_t)
operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
^
/usr/include/c++/4.8/bits/unique_ptr.h:495:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:81:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:489:5: note: template<class _Tp, class _Dp, class _Up, class _Ep> bool std::operator==(const std::unique_ptr<_Tp, _Dp>&, const std::unique_ptr<_Up, _Ep>&)
operator==(const unique_ptr<_Tp, _Dp>& __x,
^
/usr/include/c++/4.8/bits/unique_ptr.h:489:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:79:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/functional:2543:5: note: template<class _Res, class ... _Args> bool std::operator==(std::nullptr_t, const std::function<_Res(_ArgTypes ...)>&)
operator==(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
^
/usr/include/c++/4.8/functional:2543:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: cannot convert ‘__first.MyList<T, Allocator>::iterator::operator*<int, std::allocator<int> >()’ (type ‘MyList<int, std::allocator<int> >::Link’) to type ‘std::nullptr_t’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/memory:79:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/functional:2537:5: note: template<class _Res, class ... _Args> bool std::operator==(const std::function<_Res(_ArgTypes ...)>&, std::nullptr_t)
operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
^
/usr/include/c++/4.8/functional:2537:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::function<_Res(_ArgTypes ...)>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/functional:55:0,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/tuple:813:5: note: template<class ... _TElements, class ... _UElements> constexpr bool std::operator==(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
operator==(const tuple<_TElements...>& __t,
^
/usr/include/c++/4.8/tuple:813:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::tuple<_Elements ...>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/tuple:39:0,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/array:228:5: note: template<class _Tp, long unsigned int _Nm> bool std::operator==(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
^
/usr/include/c++/4.8/array:228:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::array<_Tp, _Nm>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator==(const _CharT* __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: mismatched types ‘const _CharT*’ and ‘MyList<int, std::allocator<int> >::Link’
while (__first != __last && !(*__first == __val))
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:1,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2493: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>&)
operator==(const basic_string<_CharT>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2493:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /home/epezhman/cpp/Part1/assignment4/exercise_1/include/my_list.h:5,
from /home/epezhman/cpp/Part1/assignment4/src/main.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:139:46: note: ‘MyList<int, std::allocator<int> >::Link’ is not derived from ‘const std::basic_string<_CharT>’
while (__first != __last && !(*__first == __val))
It looks like your value_type and reference should use T not Link. (You want to iterate over the values, not the links containing them.) operator * and operator -> need to change appropriately.
Related
A question from a C++ newbie. Forgive me if its a simple one.
I am trying to run a *.cpp code that reads a text file and outputs a formatted file. However when running the code, I am getting some compilation errors. I have attached herewith the code and errors.
The code:
#include<iostream>
#include<iomanip>
#include<fstream>
const int cell = 1;
using namespace std;
int main()
{
int id[cell],crop[cell],n;
double root_depth1[cell], root_depth2[cell], root_depth3[cell], root_fract1[cell], root_fract2[cell], root_fract3[cell], x;
double LAI_1[cell],LAI_2[cell],LAI_3[cell],LAI_4[cell],LAI_5[cell],LAI_6[cell];
double LAI_7[cell], LAI_8[cell], LAI_9[cell], LAI_10[cell], LAI_11[cell], LAI_12[cell];
ifstream read;
read.open("veg_par_in.txt");
if(read != 0)
{
for (int i=0;i<cell;i++)
{
read>>id[i]>>crop[i]>>root_depth1[i]>>root_fract1[cell]>>root_depth2[cell]>>root_fract2[cell]>>root_depth3[cell]>>root_fract3[cell];
read>>LAI_1[i]>>LAI_2[i]>>LAI_3[i]>>LAI_4[i]>>LAI_5[i]>>LAI_6[i];
read>>LAI_7[i]>>LAI_8[i]>>LAI_9[i]>>LAI_10[i]>>LAI_11[i]>>LAI_12[i];
}
read.close();
ofstream write;
write.open("veg_par.txt");
for(int j=0;j<cell;j++)
{
write<<id[j]<<" "<<1<<endl;
write<<right<<setw(5)<<crop[j]<<" "<<fixed<<setprecision(6)<<float(1)<<fixed<<setprecision(2)<<" "<<root_depth1[j]<<" "<<root_fract1[cell];
write<<" "<<root_depth2[cell]<<" "<<root_fract2[cell]<<" "<<root_depth3[cell]<<" "<<root_fract3[cell]<<endl;
write<<" "<<fixed<<setprecision(3)<<LAI_1[j]<<" "<<LAI_2[j]<< " "<<LAI_3[j]<<" "<<LAI_4[j]<<" "<<LAI_5[j]<," "<<LAI_6[j];
write<<" "<<LAI_7[j]<<" "<<LAI_8[j]<<" "<<LAI_9[j]<<" "<<LAI_10[j]<<" "<<LAI_11[j]<<" "<<LAI_12[j]<<endl;
}
write.close();
}
else
cout<<"veg_par_in.txt file is missing.";
}
The error message:
veg_par.cpp: In function ‘int main()’:
veg_par.cpp:17:10: error: no match for ‘operator!=’ (operand types are ‘std::ifstream {aka std::basic_ifstream<char>}’ and ‘int’)
if(read != 0)
veg_par.cpp:17:10: note: candidate: operator!=(int, int) <built-in>
veg_par.cpp:17:10: note: no known conversion for argument 1 from ‘std::ifstream {aka std::basic_ifstream<char>}’ to ‘in ’
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iosfwd:40:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.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/6.4.0/include/c++/bits/postypes.h:221:5: note: template argument deduction/substitution fa iled:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::fpos<_StateT>’
if(read != 0)
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_algobase.h:64:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_pair.h:448:5: note: candidate: template<class _T1, class _T2> con stexpr 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/6.4.0/include/c++/bits/stl_pair.h:448:5: note: template argument deduction/substitution fa iled:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::pair<_T1, _T2>’
if(read != 0)In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_iterator.h:304: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/6.4.0/include/c++/bits/stl_iterator.h:304:5: note: template argument deduction/substitutio n failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::reverse_iterato r<_Iterator>’
if(read != 0)
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_iterator.h:361:5: note: candidate: template<class _IteratorL, cla ss _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/6.4.0/include/c++/bits/stl_iterator.h:361:5: note: template argument deduction/substitutio n failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::reverse_iterato r<_Iterator>’
if(read != 0)
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_iterator.h:1125:5: note: candidate: template<class _IteratorL, cl ass _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/6.4.0/include/c++/bits/stl_iterator.h:1125:5: note: template argument deduction/substituti on failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::move_iterator<_ IteratorL>’
if(read != 0)
^In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_algobase.h:67:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/stl_iterator.h:1131:5: note: candidate: template<class _Iterator> boo l 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/6.4.0/include/c++/bits/stl_iterator.h:1131:5: note: template argument deduction/substituti on failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::move_iterator<_ IteratorL>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/string:41:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/allocator.h:158:5: note: candidate: template<class _T1, class _T2> bo ol std::operator!=(const std::allocator<_CharT>&, const std::allocator<_T2>&)
operator!=(const allocator<_T1>&, const allocator<_T2>&)
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/allocator.h:158:5: note: template argument deduction/substitution f ailed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::allocator<_Char T>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/string:41:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/allocator.h:164:5: note: candidate: template<class _Tp> bool std::ope rator!=(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/allocator.h:164:5: note: template argument deduction/substitution f ailed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::allocator<_Char T>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/string:52:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/basic_string.h:5112:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_Ch arT, _Traits, _Alloc>&)
operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/basic_string.h:5112:5: note: template argument deduction/substituti on failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::basic_string<_C harT, _Traits, _Alloc>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/string:52:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/basic_string.h:5125: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/6.4.0/include/c++/bits/basic_string.h:5125:5: note: template argument deduction/substituti on failed:
veg_par.cpp:17:13: note: mismatched types ‘const _CharT*’ and ‘std::basic_ifstream<char>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/string:52:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/basic_string.h:5137: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/6.4.0/include/c++/bits/basic_string.h:5137:5: note: template argument deduction/substituti on failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::basic_string<_C harT, _Traits, _Alloc>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ios_base.h:46:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/system_error:311: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/6.4.0/include/c++/system_error:311:3: note: no known conversion for argument 1 from ‘std:: ifstream {aka std::basic_ifstream<char>}’ to ‘const std::error_code&’
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/system_error:315: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/6.4.0/include/c++/system_error:315:3: note: no known conversion for argument 1 from ‘std:: ifstream {aka std::basic_ifstream<char>}’ to ‘const std::error_code&’
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/system_error:319: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/6.4.0/include/c++/system_error:319:3: note: no known conversion for argument 1 from ‘std:: ifstream {aka std::basic_ifstream<char>}’ to ‘const std::error_condition&’
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/system_error:323: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/6.4.0/include/c++/system_error:323:3: note: no known conversion for argument 1 from ‘std:: ifstream {aka std::basic_ifstream<char>}’ to ‘const std::error_condition&’
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_facets.h:48:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/basic_ios.h:37,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ios:44,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iostream:39,
from veg_par.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/streambuf_iterator.h:210:5: note: candidate: template<class _CharT, c lass _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/6.4.0/include/c++/bits/streambuf_iterator.h:210:5: note: template argument deduction/subst itution failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::istreambuf_iter ator<_CharT, _Traits>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/tuple:39:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:37,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_conv.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/locale:43,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iomanip:43,
from veg_par.cpp:3:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/array:246:5: note: candidate: template<class _Tp, long unsigned int _Nm> b ool std::operator!=(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/array:246:5: note: template argument deduction/substitution failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::array<_Tp, _Nm ’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:37:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_conv.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/locale:43,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iomanip:43,
from veg_par.cpp:3:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/tuple:1367:5: note: candidate: template<class ... _TElements, class ... _U Elements> constexpr bool std::operator!=(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
operator!=(const tuple<_TElements...>& __t,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/tuple:1367:5: note: template argument deduction/substitution failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::tuple<_Elements ...>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_conv.h:41:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/locale:43,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iomanip:43,
from veg_par.cpp:3:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:667:5: note: candidate: template<class _Tp, class _Dp, c lass _Up, class _Ep> bool std::operator!=(const std::unique_ptr<_Tp, _Dp>&, const std::unique_ptr<_Up, _Ep>&)
operator!=(const unique_ptr<_Tp, _Dp>& __x,
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:667:5: note: template argument deduction/substitution failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_conv.h:41:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/locale:43,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iomanip:43,
from veg_par.cpp:3:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:673:5: note: candidate: template<class _Tp, class _Dp> b ool std::operator!=(const std::unique_ptr<_Tp, _Dp>&, std::nullptr_t)
operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:673:5: note: template argument deduction/substitution failed:
veg_par.cpp:17:13: note: ‘std::ifstream {aka std::basic_ifstream<char>}’ is not derived from ‘const std::unique_ptr<_Tp, _Dp>’
if(read != 0)
^
In file included from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/locale_conv.h:41:0,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/locale:43,
from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/iomanip:43,
from veg_par.cpp:3:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:678:5: note: candidate: template<class _Tp, class _Dp> b ool std::operator!=(std::nullptr_t, const std::unique_ptr<_Tp, _Dp>&)
operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
^~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/unique_ptr.h:678:5: note: template argument deduction/substitution failed:
veg_par.cpp:17:13: note: mismatched types ‘const std::unique_ptr<_Tp, _Dp>’ and ‘int’
if(read != 0)
^
veg_par.cpp:34:109: error: expected primary-expression before ‘,’ token
write<<" "<<fixed<<setprecision(3)<<LAI_1[j]<<" "<<LAI_2[j]<< " "<<LAI_3[j]<<" "<<LAI_4[j]<<" "<<LAI_5[j]<," "<<LAI_6[j ];
^
veg_par.cpp:34:113: error: invalid operands of types ‘const char [2]’ and ‘double’ to binary ‘operator<<’
write<<" "<<fixed<<setprecision(3)<<LAI_1[j]<<" "<<LAI_2[j]<< " "<<LAI_3[j]<<" "<<LAI_4[j]<<" "<<LAI_5[j]<," "<<LAI_6[j ];
~~~^~~~~~~~~ ~
The first error says there is no match for 'operator!=' with operand types char and int. I have been looking into this error and found out this may be related with the operator comparing two types of operand types. Here, 'read' is a stream variable and it has a data type of char and the operator is comparing two data types. I am pretty sure that all the errors while running this code arises from the operator comparing the two data types.
I used "g++ -g veg_par.cpp -o a.exe" for compilation.
How do I solve this error? Any help would be highly appreciated.
The first error says there is no match for 'operator!=' with operand types char and int
Not quite. Your problem is in this expression read != 0. It's attempting to compare an std::ifstream to an int. Since the former is a class type, overloaded operators must by considered, as well as any user defined conversions to int. There are no such conversions, and no operator!= defined. So you can't write such a comparison.
Now, that does't mean you use read in the condition of an if-statement. It just means you must use it in one of the supported ways. Those being if(read) and if(!read). std::ifstream has an operator! as well is allowing contextual conversions to bool.
This is for a single error. I had to cut it down in order to post it here. How to disable this madness ? (g++ 5.3.1)
user#computer:~/projectClient# ./build
project/update.cpp: In function ‘bool is_recentlyProcessed(IntervalTime, ulong)’:
project/update.cpp:71:80: error: no match for ‘operator==’ (operand types are ‘std::_Rb_tree_const_iterator<long unsigned int>’ and ‘std::map<IntervalTime, std::set<long unsigned int> >::iterator {aka std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > >}’)
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/set:60:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_tree.h:312:7: note: candidate: bool std::_Rb_tree_const_iterator<_Tp>::operator==(const _Self&) const [with _Tp = long unsigned int; std::_Rb_tree_const_iterator<_Tp>::_Self = std::_Rb_tree_const_iterator<long unsigned int>]
operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
^
/usr/include/c++/5/bits/stl_tree.h:312:7: note: no known conversion for argument 1 from ‘std::map<IntervalTime, std::set<long unsigned int> >::iterator {aka std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > >}’ to ‘const _Self& {aka const std::_Rb_tree_const_iterator<long unsigned int>&}’
In file included from /usr/include/c++/5/stack:61:0,
from /usr/include/jsoncpp/json/reader.h:15,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_stack.h:246:5: note: candidate: template<class _Tp, class _Seq> bool std::operator==(const std::stack<_Tp, _Seq>&, const std::stack<_Tp, _Seq>&)
operator==(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y)
^
/usr/include/c++/5/bits/stl_stack.h:246:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::stack<_Tp, _Seq>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:2220:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator==(const std::deque<_Tp, _Alloc>&, const std::deque<_Tp, _Alloc>&)
operator==(const deque<_Tp, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:2220:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::deque<_Tp, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:272:5: note: candidate: template<class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> bool std::operator==(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _RefR, _PtrR>&)
operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:272:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/deque:64:0,
from /usr/include/jsoncpp/json/reader.h:13,
from /usr/include/jsoncpp/json/json.h:11,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_deque.h:265:5: note: candidate: template<class _Tp, class _Ref, class _Ptr> bool std::operator==(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _Ref, _Ptr>&)
operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
^
/usr/include/c++/5/bits/stl_deque.h:265:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/map:62:0,
from /usr/include/jsoncpp/json/value.h:17,
from /usr/include/jsoncpp/json/json.h:10,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_multimap.h:974:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_multimap.h:974:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/map:61:0,
from /usr/include/jsoncpp/json/value.h:17,
from /usr/include/jsoncpp/json/json.h:10,
from project/../parser/parser.h:5,
from project/../data.h:5,
from project/update.cpp:12:
/usr/include/c++/5/bits/stl_map.h:1073:5: note: candidate: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_map.h:1073:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:347:5: note: candidate: template<class _Tp> bool std::operator==(std::nullptr_t, const std::shared_ptr<_Tp1>&)
operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
^
/usr/include/c++/5/bits/shared_ptr.h:347:5: note: template argument deduction/substitution failed:
project/update.cpp:71:15: note: cannot convert ‘std::find<std::_Rb_tree_const_iterator<long unsigned int>, long unsigned int>((& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::begin<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), (& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::end<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), id)’ (type ‘std::_Rb_tree_const_iterator<long unsigned int>’) to type ‘std::nullptr_t’
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:342:5: note: candidate: template<class _Tp> bool std::operator==(const std::shared_ptr<_Tp1>&, std::nullptr_t)
operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
^
/usr/include/c++/5/bits/shared_ptr.h:342:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::shared_ptr<_Tp1>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/memory:82:0,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr.h:336:5: note: candidate: template<class _Tp1, class _Tp2> bool std::operator==(const std::shared_ptr<_Tp1>&, const std::shared_ptr<_Tp2>&)
operator==(const shared_ptr<_Tp1>& __a,
^
/usr/include/c++/5/bits/shared_ptr.h:336:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::shared_ptr<_Tp1>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1194:5: note: candidate: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(std::nullptr_t, const std::__shared_ptr<_Tp, _Lp>&)
operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
^
/usr/include/c++/5/bits/shared_ptr_base.h:1194:5: note: template argument deduction/substitution failed:
project/update.cpp:71:15: note: cannot convert ‘std::find<std::_Rb_tree_const_iterator<long unsigned int>, long unsigned int>((& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::begin<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), (& recentlyProcessed.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<IntervalTime, std::set<long unsigned int>, std::less<IntervalTime>, std::allocator<std::pair<const IntervalTime, std::set<long unsigned int> > > >(it))->std::set<_Key, _Compare, _Alloc>::end<long unsigned int, std::less<long unsigned int>, std::allocator<long unsigned int> >(), id)’ (type ‘std::_Rb_tree_const_iterator<long unsigned int>’) to type ‘std::nullptr_t’
return !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1189:5: note: candidate: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp, _Lp>&, std::nullptr_t)
operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
^
/usr/include/c++/5/bits/shared_ptr_base.h:1189:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::__shared_ptr<_Tp, _Lp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from /usr/include/c++/5/thread:40,
from project/update.cpp:7:
/usr/include/c++/5/bits/shared_ptr_base.h:1183:5: note: candidate: template<class _Tp1, class _Tp2, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const std::__shared_ptr<_Tp1, _Lp>&, const std::__shared_ptr<_Tp2, _Lp>&)
operator==(const __shared_ptr<_Tp1, _Lp>& __a,
^
/usr/include/c++/5/bits/shared_ptr_base.h:1183:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::__shared_ptr<_Tp1, _Lp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:62:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_multiset.h:825:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)
operator==(const multiset<_Key, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_multiset.h:825:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::multiset<_Key, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:61:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_set.h:842:5: note: candidate: template<class _Key, class _Compare, class _Alloc> bool std::operator==(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)
operator==(const set<_Key, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_set.h:842:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::set<_Key, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/set:60:0,
from project/update.cpp:6:
/usr/include/c++/5/bits/stl_tree.h:1273:5: note: candidate: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator==(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
operator==(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
^
/usr/include/c++/5/bits/stl_tree.h:1273:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
....
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/allocator.h:134:5: note: candidate: template<class _Tp> bool std::operator==(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
^
/usr/include/c++/5/bits/allocator.h:134:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/allocator.h:128:5: note: candidate: template<class _T1, class _T2> bool std::operator==(const std::allocator<_Tp>&, const std::allocator<_Tp>&)
operator==(const allocator<_T1>&, const allocator<_T2>&)
^
/usr/include/c++/5/bits/allocator.h:128:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/char_traits.h:40:0,
from /usr/include/c++/5/string:40,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/bits/postypes.h:216:5: note: candidate: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^
/usr/include/c++/5/bits/postypes.h:216:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::fpos<_StateT>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1071:5: note: candidate: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator==(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1071:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::move_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1065:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator==(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1065:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::move_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:342:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator==(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:342:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:292:5: note: candidate: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator==(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:292:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/utility:70:0,
from /usr/include/c++/5/algorithm:60,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:214:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/include/c++/5/bits/stl_pair.h:214:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const std::pair<_T1, _T2>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
from /usr/include/c++/5/bits/allocator.h:46,
from /usr/include/c++/5/string:41,
from /usr/include/c++/5/random:40,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from project/update.cpp:1:
/usr/include/c++/5/ext/new_allocator.h:139:5: note: candidate: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
^
/usr/include/c++/5/ext/new_allocator.h:139:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:827:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
^
/usr/include/c++/5/bits/stl_iterator.h:827:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/algorithm:61,
from project/update.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:820:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
^
/usr/include/c++/5/bits/stl_iterator.h:820:5: note: template argument deduction/substitution failed:
project/update.cpp:71:105: note: ‘std::_Rb_tree_const_iterator<long unsigned int>’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
urn !(find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) == recentlyProcessed.end());
^
user#computer:~/projectClient#
Here's the build command (it doesn't make a difference if i remove -Wall):
g++ -O3 -Wall -Wno-deprecated-declarations -Wno-unused-variable -Wno-format-contains-nul -std=c++11 -D${JSON} \
-lpthread -lboost_system -lboost_chrono -lssl -lcrypto -ljsoncpp \
-o bin/client client.cpp common.cpp update.cpp
While the error spew is daunting at initial glance, it can be helpful in tricky cases. Just start at the top and work your way down until you figure out what the problem is.
In this case it looks like you're trying to compare a std::_Rb_tree_const_iterator<long unsigned int> with a std::_Rb_tree_iterator<std::pair<const IntervalTime, std::set<long unsigned int> > > which are iterators to completely different types of objects.
It seems that find(recentlyProcessed[it].begin(), recentlyProcessed[it].end(), id) returns an interator to a different container than what recentlyProcessed.end is - note that recentlyProcessed.end doesn't have an index.
Probably you need to compare with recentlyProcessed[it].end or recentlyProcessed[it].end() instead.
I have overloaded allocator for most of the stl containers below is the code. The code is from here
#include <iostream>
#include <vector>
#include <list>
namespace outside
{
template<typename T>
struct MyAllocator
{
typedef typename std::allocator<T>::value_type value_type;
typedef typename std::allocator<T>::pointer pointer;
typedef typename std::allocator<T>::const_pointer const_pointer;
typedef typename std::allocator<T>::reference reference;
typedef typename std::allocator<T>::const_reference const_reference;
typedef typename std::allocator<T>::size_type size_type;
pointer allocate (size_type n, typename std::allocator<void>::const_pointer hint=0)
{
std::cerr << "allocate..." << std::endl;
return std::allocator<T>{}.allocate(n, hint);
}
void deallocate (pointer p, size_type n)
{
std::cerr << "deallocate..." << std::endl;
return std::allocator<T>{}.deallocate(p, n);
}
template <class Type> struct rebind
{
typedef MyAllocator<Type> other;
};
MyAllocator()
{
}
MyAllocator(const MyAllocator<T>& other )
{
}
template< class U >
MyAllocator( const MyAllocator<U>& other )
{
}
};
} // namespace outside
namespace outer
{
template<class T>
using vector = ::std::vector<T, outside::MyAllocator<T>>;
template<class T>
using list = ::std::list<T, outside::MyAllocator<T>>;
}
int main()
{
outer::vector<int> myVector1;
outer::vector<int> myVector2;
myVector1.push_back(10);
myVector1.push_back(20);
// myVector2 = myVector1; // Getting compilation error
for (auto i = myVector1.begin(); i != myVector1.end(); ++i) {
std::cout << *i << ' ';
}
std::list<int> myList1;
std::list<int> myList2;
myList2 = myList1; // // No compilation error
}
Copying one vector to another vector is giving me error. While for the same code copying one list to another list is working fine.
Compilation error
included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc: In instantiation of 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = outside::MyAllocator<int>]':
prog.cpp:59:15: required from here
/usr/include/c++/5/bits/vector.tcc:176:37: error: no match for 'operator!=' (operand types are 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' and 'const _Tp_alloc_type {aka const outside::MyAllocator<int>}')
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/iosfwd:40:0,
from /usr/include/c++/5/ios:38,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/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/include/c++/5/bits/postypes.h:221:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::fpos<_StateT>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:227:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/include/c++/5/bits/stl_pair.h:227:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::pair<_T1, _T2>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:304:5: note: candidate: template<class _Iterator> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator!=(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:304:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::reverse_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:354:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator!=(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:354:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::reverse_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1077:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator!=(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator!=(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1077:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::move_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1083:5: note: candidate: template<class _Iterator> bool std::operator!=(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator!=(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1083:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::move_iterator<_Iterator>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/allocator.h:140: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/include/c++/5/bits/allocator.h:140:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::allocator<_CharT>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:41:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/allocator.h:146: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/include/c++/5/bits/allocator.h:146:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::allocator<_CharT>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4948: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/include/c++/5/bits/basic_string.h:4948:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4960: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/include/c++/5/bits/basic_string.h:4960:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: mismatched types 'const _CharT*' and 'outside::MyAllocator<int>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4972: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/include/c++/5/bits/basic_string.h:4972:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/bits/ios_base.h:46:0,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/system_error:311: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/include/c++/5/system_error:311:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_code&'
/usr/include/c++/5/system_error:315: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/include/c++/5/system_error:315:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_code&'
/usr/include/c++/5/system_error:319: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/include/c++/5/system_error:319:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_condition&'
/usr/include/c++/5/system_error:323:3: note: candidate: bool std::operator!=(const std::error_condition&, const std::error_condition&)
operator!=(const error_condition& __lhs,
^
/usr/include/c++/5/system_error:323:3: note: no known conversion for argument 1 from 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' to 'const std::error_condition&'
In file included from /usr/include/c++/5/bits/locale_facets.h:48:0,
from /usr/include/c++/5/bits/basic_ios.h:37,
from /usr/include/c++/5/ios:44,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/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/include/c++/5/bits/streambuf_iterator.h:210:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::istreambuf_iterator<_CharT, _Traits>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/vector:64:0,
from prog.cpp:2:
/usr/include/c++/5/bits/stl_vector.h:1535:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator!=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/5/bits/stl_vector.h:1535:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::vector<_Tp, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/list:63:0,
from prog.cpp:3:
/usr/include/c++/5/bits/stl_list.h:291:5: note: candidate: template<class _Val> bool std::operator!=(const std::_List_iterator<_Tp>&, const std::_List_const_iterator<_Val>&)
operator!=(const _List_iterator<_Val>& __x,
^
/usr/include/c++/5/bits/stl_list.h:291:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::_List_iterator<_Tp>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
In file included from /usr/include/c++/5/list:63:0,
from prog.cpp:3:
/usr/include/c++/5/bits/stl_list.h:1843:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator!=(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)
operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
^
/usr/include/c++/5/bits/stl_list.h:1843:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/vector:69:0,
from prog.cpp:2:
/usr/include/c++/5/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::list<_Tp, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
I am trying to understand why this is the case and solution for this problem ?
The key part of the exception is hundreds of lines into it:
In file included from /usr/local/include/c++/5.2.0/vector:64:0,
from main.cpp:2: /usr/local/include/c++/5.2.0/bits/stl_vector.h:1535:5: note: candidate: 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/local/include/c++/5.2.0/bits/stl_vector.h:1535:5: note: template argument deduction/substitution failed:
In file included from /usr/local/include/c++/5.2.0/vector:69:0,
from main.cpp:2:
/usr/local/include/c++/5.2.0/bits/vector.tcc:176:37: note: 'std::_Vector_base<int, outside::MyAllocator<int> >::_Tp_alloc_type {aka outside::MyAllocator<int>}' is not derived from 'const std::vector<_Tp, _Alloc>'
&& _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
^
vector::operator= requires vector::operator!=, which requires allocator::operator!=, which doesn't exist. Without it, the function can't be created. Simply add an operator!= to your allocator. While you're at it, also make sure you have all the other required allocator functions. If memory serves me right, you're missing a fair number.
Change the definition to struct MyAllocator: public std::allocator<T> and the code will compile.
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've been curious about why one error can cause the compiler to generate a very long list of error messages. The following example is the result of an erroneous comparison between an element of a vector<string> and NULL at line 100 of main.cpp under GCC 4.8.1:
> g++ -g3 -std=c++11 main.cpp functions.cpp
main.cpp: In function ‘int main()’:
main.cpp:100:24: error: no match for ‘operator==’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ and ‘long int’)
if(args[1] == NULL) {
^
main.cpp:100:24: note: candidates are:
In file included from /usr/include/c++/4.8/iosfwd:40:0,
from /usr/include/c++/4.8/ios:38,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/postypes.h:216:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^
/usr/include/c++/4.8/bits/postypes.h:216:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::fpos<_StateT>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_pair.h:214:5: note: template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/include/c++/4.8/bits/stl_pair.h:214:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::pair<_T1, _T2>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:291:5: note: template<class _Iterator> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator==(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:291:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:341:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator==(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:341:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::reverse_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:1031:5: note: template<class _IteratorL, class _IteratorR> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator==(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:1031:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::move_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:1037:5: note: template<class _Iterator> bool std::operator==(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator==(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/4.8/bits/stl_iterator.h:1037:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::move_iterator<_Iterator>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:41:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/allocator.h:128:5: note: template<class _T1, class _T2> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_T2>&)
operator==(const allocator<_T1>&, const allocator<_T2>&)
^
/usr/include/c++/4.8/bits/allocator.h:128:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::allocator<_CharT>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:41:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/allocator.h:133:5: note: template<class _Tp> bool std::operator==(const std::allocator<_CharT>&, const std::allocator<_CharT>&)
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
^
/usr/include/c++/4.8/bits/allocator.h:133:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::allocator<_CharT>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2486:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2486:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘long int’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2493: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>&)
operator==(const basic_string<_CharT>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2493:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const std::basic_string<_CharT>’ and ‘long int’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator==(const _CharT* __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2507:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const _CharT*’ and ‘std::basic_string<char>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/string:52:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8/bits/basic_string.h:2519:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: mismatched types ‘const _CharT*’ and ‘long int’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/locale_facets.h:48:0,
from /usr/include/c++/4.8/bits/basic_ios.h:37,
from /usr/include/c++/4.8/ios:44,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: 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/include/c++/4.8/bits/streambuf_iterator.h:204:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::istreambuf_iterator<_CharT, _Traits>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/vector:64:0,
from main.h:16,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_vector.h:1403:5: note: template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/4.8/bits/stl_vector.h:1403:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::vector<_Tp, _Alloc>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/x86_64-suse-linux/bits/c++allocator.h:33:0,
from /usr/include/c++/4.8/bits/allocator.h:46,
from /usr/include/c++/4.8/string:41,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/ext/new_allocator.h:139:5: note: template<class _Tp> bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
^
/usr/include/c++/4.8/ext/new_allocator.h:139:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:811: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>&)
operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
^
/usr/include/c++/4.8/bits/stl_iterator.h:811:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
if(args[1] == NULL) {
^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8/bits/char_traits.h:39,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from main.h:13,
from main.cpp:12:
/usr/include/c++/4.8/bits/stl_iterator.h:805: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>&)
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
^
/usr/include/c++/4.8/bits/stl_iterator.h:805:5: note: template argument deduction/substitution failed:
In file included from /usr/include/unistd.h:226:0,
from main.h:20,
from main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
if(args[1] == NULL) {
^
This can make it very hard to understand the problem. What is the reason for this behavior?
If you have an expression of the form vec == NULL, the compiler applies ADL to find an appropriate operator== to call. If it can't find a single one it outputs all operator== candidates found in all namespaces considered, and the reason they did not fit here.
One of those can look like this:
In file included from [..] main.cpp:12:
[..]:216:5: note: template<class _StateT> bool std::operator==(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
^
[..]:216:5: note: template argument deduction/substitution failed:
In file included from [..] main.cpp:12:
main.cpp:100:27: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type {aka std::basic_string<char>}’ is not derived from ‘const std::fpos<_StateT>’
if(args[1] == NULL) {
^
We couldn't match the first parameter to the first argument as std::string isn't derived from any fpos-specialization (also std::string doesn't have any appropriate conversion operators, but that isn't mentioned here). If you defined an operator== that can't be found/called, wouldn't you like to know the reason from the compilers view? (Especially if you don't have a clue yourself)
This can be very useful at times. When it isn't, ignore it. In most cases C++-programmers immediately see and understand what causes the error message (and its enourmos note-section).
This may help in situations like this (you got a large volume of template related message).
Whether your are using make or directly using the compiler, try to pipe the stderr to a file in my example
make 2> error.log
The use any editor open the error.log file. Search for file name of the source code you wrote. There should only be one or two lines that are interesting to you. For example:
mysourcefile.cpp:51:20: required from here
This is where the problem happened; look harder here.