C++ what is wrong with this function - c++

void webparser(const string siteurl,string filename)
{
stringstream ss;
ss << "lynx -dump '" << siteurl << "'" > filename;
system(ss.str().c_str());
}
How do I use filename instead of file.txt in the above example?
Initially my line for ss was
ss << "lynx -dump '" << siteurl << "' > file.txt";
But I decided to change it to use the value from a parameter, so I added filename.
Below is my error message
main.cpp: In function ‘void webparser(std::string, std::string)’:
main.cpp:244:46: error: no match for ‘operator>’ in ‘std::operator<< [with _Traits = std::char_traits<char>]((* & std::operator<< [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]((* & std::operator<< [with _Traits = std::char_traits<char>]((* & ss.std::basic_stringstream<char>::<anonymous>.std::basic_iostream<char>::<anonymous>), ((const char*)"lynx -dump \'"))), (* & siteurl))), ((const char*)"\'")) > filename’
main.cpp:244:46: note: candidates are:
/usr/include/c++/4.6/bits/stl_pair.h:220:5: note: template<class _T1, class _T2> bool std::operator>(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/include/c++/4.6/bits/stl_iterator.h:303:5: note: template<class _Iterator> bool std::operator>(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.6/bits/stl_iterator.h:353:5: note: template<class _IteratorL, class _IteratorR> bool std::operator>(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.6/bits/basic_string.h:2547:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/basic_string.h:2559:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.6/bits/basic_string.h:2571:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator>(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/stl_iterator.h:842:5: note: template<class _Iterator, class _Container> bool __gnu_cxx::operator>(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
/usr/include/c++/4.6/bits/stl_iterator.h:836: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>&)
make: *** [main.o] Error 1

Replace
ss << "lynx -dump '" << siteurl << "'" > filename;
with
ss << "lynx -dump '" << siteurl << "'" << filename;
or, to be consistent with your original code:
ss << "lynx -dump '" << siteurl << "' > " << filename;

Related

Extending iterator of boost::filtered to support operator+ overload

I would like to add a operator+ overload to boost::filter_iterator as in below example. However I am getting an error in the resolution of the template parameters to the operator+ overload function.
#include <iostream>
#include <vector>
#include <boost/range/adaptor/filtered.hpp>
template <typename TPredicate, typename TRange>
class Filtered_Range : public boost::filtered_range<TPredicate, TRange>
{
public:
Filtered_Range(TPredicate Predicate, TRange& Range) : boost::filtered_range<TPredicate, TRange>(Predicate, Range) {}
size_t size() const { return std::distance(this->begin(), this->end()); }
auto operator[](size_t Index) const
{
assert(Index < this->size());
auto It = this->begin();
std::advance(It, Index);
return *It;
}
};
template<typename TPredicate, typename TRange>
typename Filtered_Range<TPredicate, TRange>::filter_iterator&
operator+(typename
Filtered_Range<TPredicate, TRange>::filter_iterator& f, int32_t x ) {
std::cout << "Custom overload\n";
return std::advance(f, x);
}
int main() {
const std::vector<int> nums{1, 2, 3, 4, 5, 6, 7, 8, 9};
auto even_only_custom = Filtered_Range([] (auto n) { return (n % 2 == 0); }, nums);
auto x = even_only_custom.begin();
std::cout << "First Value = " << *(x) << "\n";
std::cout << "Second Value = " << *(x + 1); //error here
}
GCC 11.2 error message
<source>: In function 'int main()':
<source>:47:43: error: no match for 'operator+' (operand types are 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' and 'int')
47 | std::cout << "Second Value = " << *(x + 1);
| ~ ^ ~
| | |
| | int
| boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >
<source>:28:1: note: candidate: 'template<class TPredicate, class TRange> typename Filtered_Range<TPredicate, TRange>::filter_iterator& operator+(typename Filtered_Range<TPredicate, TRange>::filter_iterator&, int32_t)'
28 | operator+(typename
| ^~~~~~~~
<source>:28:1: note: template argument deduction/substitution failed:
<source>:47:45: note: couldn't deduce template parameter 'TPredicate'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h:67,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/char_traits.h:39,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator.h:568:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&)'
568 | operator+(typename reverse_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator.h:568:5: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h:67,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/char_traits.h:39,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator.h:1646:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename std::move_iterator<_IteratorL>::difference_type, const std::move_iterator<_IteratorL>&)'
1646 | operator+(typename move_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator.h:1646:5: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6094:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
6094 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6094:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:56,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.tcc:1169:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
1169 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.tcc:1169:5: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'const _CharT*' and 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:56,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.tcc:1189:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
1189 | operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.tcc:1189:5: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6131:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
6131 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6131:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6147:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
6147 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6147:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6159:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
6159 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6159:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6165:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
6165 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6165:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6171:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
6171 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6171:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6193:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
6193 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6193:5: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'const _CharT*' and 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6199:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
6199 | operator+(_CharT __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6199:5: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6205:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*)'
6205 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6205:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/string:55,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/locale_classes.h:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ios_base.h:41,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:42,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6211:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, _CharT)'
6211 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/basic_string.h:6211:5: note: template argument deduction/substitution failed:
<source>:47:45: note: 'boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h:67,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/char_traits.h:39,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ios:40,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/ostream:38,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/iostream:39,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator.h:1242:5: note: candidate: 'template<class _Iterator, class _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::operator+(typename __gnu_cxx::__normal_iterator<_Iterator, _Container>::difference_type, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
1242 | operator+(typename __normal_iterator<_Iterator, _Container>::difference_type
| ^~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator.h:1242:5: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'int'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
In file included from /opt/compiler-explorer/libs/boost_1_67_0/boost/range/iterator_range_core.hpp:27,
from /opt/compiler-explorer/libs/boost_1_67_0/boost/range/iterator_range.hpp:13,
from /opt/compiler-explorer/libs/boost_1_67_0/boost/range/adaptor/filtered.hpp:16,
from <source>:3:
/opt/compiler-explorer/libs/boost_1_67_0/boost/iterator/iterator_facade.hpp:955:3: note: candidate: 'template<class Derived, class V, class TC, class R, class D> typename boost::iterators::enable_if<boost::iterators::detail::is_traversal_at_least<TC, boost::iterators::random_access_traversal_tag>, Derived>::type boost::iterators::operator+(const boost::iterators::iterator_facade<Derived1, V1, TC1, Reference1, Difference1>&, typename Derived::difference_type)'
955 | BOOST_ITERATOR_FACADE_PLUS((
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/boost_1_67_0/boost/iterator/iterator_facade.hpp:955:3: note: template argument deduction/substitution failed:
/opt/compiler-explorer/libs/boost_1_67_0/boost/iterator/iterator_facade.hpp: In substitution of 'template<class Derived, class V, class TC, class R, class D> typename boost::iterators::enable_if<boost::iterators::detail::is_traversal_at_least<TC, boost::iterators::random_access_traversal_tag>, Derived>::type boost::iterators::operator+(const boost::iterators::iterator_facade<Derived1, V1, TC1, Reference1, Difference1>&, typename Derived::difference_type) [with Derived = boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > >; V = int; TC = boost::iterators::bidirectional_traversal_tag; R = const int&; D = long int]':
<source>:47:45: required from here
/opt/compiler-explorer/libs/boost_1_67_0/boost/iterator/iterator_facade.hpp:955:3: error: no type named 'type' in 'struct boost::iterators::enable_if<boost::iterators::detail::is_traversal_at_least<boost::iterators::bidirectional_traversal_tag, boost::iterators::random_access_traversal_tag>, boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main()::<lambda(auto:2)>, bool>, __gnu_cxx::__normal_iterator<const int*, std::vector<int> > > >'
/opt/compiler-explorer/libs/boost_1_67_0/boost/iterator/iterator_facade.hpp:960:3: note: candidate: 'template<class Derived, class V, class TC, class R, class D> typename boost::iterators::enable_if<boost::iterators::detail::is_traversal_at_least<TC, boost::iterators::random_access_traversal_tag>, Derived>::type boost::iterators::operator+(typename Derived::difference_type, const boost::iterators::iterator_facade<Derived1, V1, TC1, Reference1, Difference1>&)'
960 | BOOST_ITERATOR_FACADE_PLUS((
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/boost_1_67_0/boost/iterator/iterator_facade.hpp:960:3: note: template argument deduction/substitution failed:
<source>:47:45: note: mismatched types 'const boost::iterators::iterator_facade<Derived1, V1, TC1, Reference1, Difference1>' and 'int'
47 | std::cout << "Second Value = " << *(x + 1);
| ^
Execution build compiler returned: 1
Any pointers on the mistake and possible solutions will be appreciated.
Thanks!
In
template <typename T>
void foo(typename T::nested_type) {}
T is in non-deduced context¹. This means that the only way you can get this to work is by using SFINAE.
namespace detail {
template <typename T> struct is_filt_it : std::false_type { };
template <typename... Args>
struct is_filt_it<boost::filter_iterator<Args...>> : std::true_type { };
} // namespace detail
template <typename It>
static decltype(auto) operator+(It it, std::enable_if_t<detail::is_filt_it<It>::value, int32_t> x)
{
return std::next(it, x);
}
Now the overload always participates, but gets discarded by SFINAE for non-filter_iterator arguments:
Live On Coliru
#undef NDEBUG
#include <boost/range/adaptor/filtered.hpp>
#include <iostream>
#include <vector>
template <typename TPredicate, typename TRange>
struct Filtered_Range : boost::filtered_range<TPredicate, TRange> {
using base_type = boost::filtered_range<TPredicate, TRange>;
using base_type::base_type;
auto operator[](size_t i) const {
assert(i < this->size());
return *std::next(base_type::begin(), i);
}
};
template <typename TPredicate, typename TRange>
Filtered_Range(TPredicate const&, TRange const&) -> Filtered_Range<TPredicate, TRange>;
namespace detail {
template <typename T> struct is_filt_it : std::false_type { };
template <typename... Args>
struct is_filt_it<boost::filter_iterator<Args...>> : std::true_type { };
} // namespace detail
template <typename It>
static decltype(auto) operator+(It it, std::enable_if_t<detail::is_filt_it<It>::value, int32_t> x)
{
return std::next(it, x);
}
int main() {
std::vector nums{1, 2, 3, 4, 5, 6, 7, 8, 9};
auto evens = Filtered_Range([](auto n) { return (n % 2 == 0); }, nums);
auto it = evens.begin();
std::cout << "First Value = " << *(it) << "\n";
std::cout << "Second Value = " << *(it + 1) << "\n";
}
Prints
First Value = 2
Second Value = 4
¹ see also e.g. What is a nondeduced context?
Controlling Instantiations
To limit operator+ support for the custom range subclass only, you have to make the iterator type distinguishable.
The "tired" way would be to subclass/wrap the iterator and delegate all of the range interface to work with those instead.
The "wired" way would be wrap the Predicate (which appears as the first template argument for the filter_iterator type!). That way we can look "inside" the filter_iterator's arguments to detect when the predicate is suitably "tagged".
Attempt #1 (Naive)
namespace MyLib {
template <typename F> struct Tagged : F {
Tagged(F f) : F(std::move(f)) {}
using F::operator();
};
} // namespace MyLib
Now, we decorate the TPredicate in our custom subclass:
template <typename TPredicate, typename TRange>
struct Filtered_Range : boost::filtered_range<MyLib::Tagged<TPredicate>, TRange> {
using base_type = boost::filtered_range<MyLib::Tagged<TPredicate>, TRange>;
using base_type::base_type;
auto operator[](size_t i) const {
assert(i < this->size());
return *std::next(base_type::begin(), i);
}
using const_iterator = typename boost::range_iterator<base_type, void>::type;
};
And we extend the is_filt_it trait to check for Tagged<> predicates:
namespace detail {
template <typename T> struct is_tagged : std::false_type { };
template <typename F> struct is_tagged<MyLib::Tagged<F>> : std::true_type { };
template <typename T, typename = void> struct is_filt_it : std::false_type { };
template <typename F, typename... Args>
struct is_filt_it<boost::filter_iterator<F, Args...>,
std::enable_if_t<is_tagged<F>::value>> : std::true_type {
};
} // namespace detail
Sadly, this breaks:
Candidate template ignored: requirement 'detail::is_filt_it<boost::iterators::filter_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<MyLib::Tagged<...>, bool>...
As you can see, Boost already had a wrapper (at least sometimes) and it breaks our detection
Attempt #2 (Galaxy Brain)
So do we have to get tedious and change the actual iterator type?
No! There's a feature in C++ that is sometimes a little poisonous: Argument dependent lookup. ADL is designed to bring in "associated namespaces" for lookup. Turns out namespaces that declare the types named in template arguments (and their template arguments) are considered "associated".
So:
namespace MyLib {
namespace AdlBarrier {
template <typename F> struct Tagged : F {
Tagged(F f) : F(std::move(f)) {}
using F::operator();
};
template <typename T> constexpr bool is_tagged(T&&) { return true; }
} // namespace AdlBarrier
using AdlBarrier::Tagged;
} // namespace MyLib
Nothing changes about Filtered_Range, and:
namespace detail {
template <typename T, typename = void> struct is_filt_it : std::false_type { };
template <typename F, typename... Args>
struct is_filt_it<boost::filter_iterator<F, Args...>,
std::enable_if_t<is_tagged(static_cast<F*>(nullptr))>>
: std::true_type {
};
} // namespace detail
Now, you have special treatment for iterators from your custom range:
{
auto evens = Filtered_Range([](auto n) { return (n % 2 == 0); }, nums);
auto it = evens.begin();
std::cout << "First Value = " << *(it) << "\n";
std::cout << "Second Value = " << *(it + 1) << "\n";
}
But plain vanilla boost::filtered_range doesn't get special treatment:
{
auto odds = boost::filtered_range([](auto n) { return (n % 2 == 1); }, nums);
auto it = odds.begin();
std::cout << "First Value = " << *(it) << "\n";
std::cout << "Second Value = " << *(it + 1) << "\n"; // doesn't compile
}
See it Live: https://godbolt.org/z/xhqjqa3Gc (or correctly not-compiling: https://godbolt.org/z/67vP6TEGc)

error: no matching function for call to ‘std::__cxx11::basic_string<char>::basic_string(int&)’

Well, i have this code:
#include <iostream>
#include "Stack.h"
#include <string>
using namespace std;
int main(int argc, char* argv[]){
Stack<string> p(100);
p.push("python");
p.push("haskell");
p.push("C++");
//p.desempilhar();
if(p.isEmpty())
cout << "Pilha vazia!\n";
else
cout << "Pilha NAO vazia!\n";
if(!p.isEmpty())
cout << "Topo: " << p.peek() << endl;
else
cout << "A pilha esta vazia!!\n";
return 0;
}
and this .h code in folder /home/matheus/Codes/C++/EstruturaDeDados:
#ifndef __STACK_H_
#define __STACK_H_
#include <iostream>
using namespace std;
/*
Declarando a criação de um template para classe Stack.
Stack aqui é um template, não uma classe propriamente dita.
Ao ser declarada da maneira correta se torna uma classe de fato.
*/
template <class T>
class Stack {
private:
int top;
T* a;
int MAX;
public:
Stack(int MAX);
bool push(T x); //Adiciona um T a stack.
bool pop(); //Remove o T mais acima da stack.
T peek(); //Retorna o T mais acima da stack.
bool isEmpty();
};
//Declarando uso de um template. template <class T>
template <class T>
//"Stack<T>" é uma classe baseada no "template <class T>".
Stack<T>::Stack(int MAX){
a = new T(MAX);
top = -1;
this->MAX = MAX;
}
//Declarando uso de um template. template <class T>
template <class T>
//"Stack<T>" é uma classe baseada no "template <class T>".
bool Stack<T>::push(T x) {
if (top >= (MAX - 1)) {
cout << "Stack Overflow" << endl;
return false;
} else {
a[++top] = x;
cout << x << " pushed into stack" << endl;
return true;
}
}
//Declarando uso de um template.
template <class T>
//"Stack<T>" é uma classe baseada no "template <class T>".
bool Stack<T>::pop() {
if (top < 0) {
cout << "Stack Underflow" << endl;
return false;
}
else {
cout << a[top--] << " Popped from stack" << endl;
return true;
}
}
//Declarando uso de um template.
template <class T>
//"Stack<T>" é uma classe baseada no "template <class T>".
T Stack<T>::peek() {
if (top < 0) {
cout << "Stack is Empty" << endl;
return NULL;
} else {
return a[top];
}
}
//Declarando uso de um template.
template <class T>
//"Stack<T>" é uma <<classe baseada no "template <class T>".
bool Stack<T>::isEmpty() {
return (top < 0);
}
#endif
When i try to compile, i receive this error i cannot even understand what it is:
In file included from 21Templates.cpp:2:
/home/matheus/Codes/C++/EstruturaDeDados/Stack.h: In instantiation of ‘Stack<T>::Stack(int) [with T = std::__cxx11::basic_string<char>]’:
21Templates.cpp:8:21: required from here
/home/matheus/Codes/C++/EstruturaDeDados/Stack.h:32:9: error: no matching function for call to ‘std::__cxx11::basic_string<char>::basic_string(int&)’
a = new T(MAX);
^~~~~~~~~~
In file included from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from 21Templates.cpp:1:
/usr/include/c++/8/bits/basic_string.h:614:9: note: candidate: ‘template<class _InputIterator, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&)’
basic_string(_InputIterator __beg, _InputIterator __end,
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:614:9: note: template argument deduction/substitution failed:
In file included from 21Templates.cpp:2:
/home/matheus/Codes/C++/EstruturaDeDados/Stack.h:32:9: note: candidate expects 3 arguments, 1 provided
a = new T(MAX);
^~~~~~~~~~
In file included from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from 21Templates.cpp:1:
/usr/include/c++/8/bits/basic_string.h:576:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
basic_string(basic_string&& __str, const _Alloc& __a)
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:576:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:572:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
basic_string(const basic_string& __str, const _Alloc& __a)
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:572:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:568:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::initializer_list<_Tp>, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:568:7: note: no known conversion for argument 1 from ‘int’ to ‘std::initializer_list<char’
/usr/include/c++/8/bits/basic_string.h:541:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
basic_string(basic_string&& __str) noexcept
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:541:7: note: no known conversion for argument 1 from ‘int’ to ‘std::__cxx11::basic_string<char>&&’
/usr/include/c++/8/bits/basic_string.h:529:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:529:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:514:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ <near match>
basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:514:7: note: conversion of argument 1 would be ill-formed:
In file included from 21Templates.cpp:2:
/home/matheus/Codes/C++/EstruturaDeDados/Stack.h:32:9: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
a = new T(MAX);
^~~~~~~~~~
In file included from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from 21Templates.cpp:1:
/usr/include/c++/8/bits/basic_string.h:499:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int’
basic_string(const _CharT* __s, size_type __n,
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:499:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:481:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
basic_string(const basic_string& __str, size_type __pos,
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:481:7: note: candidate expects 4 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:465:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
basic_string(const basic_string& __str, size_type __pos,
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:465:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:450:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
basic_string(const basic_string& __str, size_type __pos,
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:450:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/8/bits/basic_string.h:437:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
basic_string(const basic_string& __str)
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:437:7: note: no known conversion for argument 1 from ‘int’ to ‘const std::__cxx11::basic_string<char>&’
/usr/include/c++/8/bits/basic_string.h:429:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:429:7: note: no known conversion for argument 1 from ‘int’ to ‘const std::allocator<char>’
/usr/include/c++/8/bits/basic_string.h:420:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
basic_string()
^~~~~~~~~~~~
/usr/include/c++/8/bits/basic_string.h:420:7: note: candidate expects 0 arguments, 1 provided
The .h is a template for a stack, im trying to code all of this with: g++ -I /home/matheus/Codes/C++/EstruturaDeDados/ -o 21Templates 21Templates.cpp, but im receiving over and over again this error.
How i solve this? And what exactly is that error?
This statement
a = new T(MAX);
tries to create an object of the type std::string from the integer value MAX. However the class std::string has no such a constructor.
It seems you mean
a = new T[MAX];
that is you want to create an array of objects of the type std::string.
This function
T Stack<T>::peek() {
if (top < 0) {
cout << "Stack is Empty" << endl;
return NULL;
} else {
return a[top];
}
}
is also wrong because creating an object of the type std::string from a null pointer results in undefined behavior. You should throw an exception for example std::out_of_range.
Pay attention to that the class has no destructor.
Instead of the dynamically allocated array you could use the class std::vector<std::string>.
If you are trying to make an array, change this line
a = new T(MAX);
to this
a = new T[MAX];
and remember to delete it later or you'll leak that memory
Stack::~Stack()
{
delete[] a;
}

c++ libconfig ambiguous overload

I'm about to compile a pretty easy 'Hello, world' using libconfig. But when I compile such code:
#include <iostream>
#include <libconfig.h++>
libconfig::Config cfg;
std::string target = "World";
int main(void)
{
try
{
cfg.readFile("greetings.cfg");
}
catch (const libconfig::FileIOException &fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return 1;
}
catch (const libconfig::ParseException &pex)
{
std::cerr << pex.getFile() << " " << pex.getLine()
<< ": " << pex.getError() << std::endl;
return 1;
}
try
{
target = cfg.lookup("target");
}
catch (const libconfig::SettingNotFoundException &nfex)
{
std::cerr << "No target set in configuration file. Using default." << std::endl;
}
std::cout << "Hello, " << target << "!" << std::endl;
return 0;
}
I have this error:
example1.cpp: In function 'int main()':
example1.cpp:28: error: ambiguous overload for 'operator=' in 'target = cfg.libconfig::Config::lookup(((const char*)"target"))
/usr/include/c++/4.2/bits/basic_string.h:490: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/include/c++/4.2/bits/basic_string.h:498: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/include/c++/4.2/bits/basic_string.h:509: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
According to Chapter 4 of the documentation, on page 19, lookup returns a Setting&, not a string.
Now, according to page 20, Setting has a bunch of implicit conversions to various types, including std::string. Here, the conversion to std::string is ambiguous in the presence of the conversion to const char*, since std::string has constructors accepting both with equal rank.
This problem is actually explicitly described on page 21, wherein resolving the ambiguity with an explicit conversion (or "cast") is suggested, or the use of the member c_str() rather than of the conversion operators:
target = cfg.lookup("target").c_str();

Mex files on Mountain Lion: explicit instantiation error

I'm working with MATLAB r2012b on Mountain Lion, and XCode version installed is 4.6.1. I've also used the patch at http://www.mathworks.it/support/solutions/en/data/1-IXBVKD/ and then I have typed "mex - setup" and selected the only option available
1: /Applications/MATLAB_R2012b.app/bin/mexopts.sh : Template Options file for building gcc MEX-files
I'm trying to use a framework for sparse modeling (written in C++) which uses mex files. In order to install the previous framework I have to call a matlab file inside the framework which calls mex function: however when I call this function I get the following message...
compilation of: -I./linalg/ -I./decomp/ -I./dictLearn/ dictLearn/mex/mexTrainDL.cpp
./linalg/linalg.h: In member function 'void Matrix<T>::print(const std::string&) const [with T = float]':
./linalg/linalg.h:1084: instantiated from 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'
./linalg/linalg.h:1084: instantiated from 'void Matrix<T>::print(const std::string&) const [with T = float]'
dictLearn/mex/mexTrainDL.cpp:197: instantiated from here
./linalg/linalg.h:1084: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
./linalg/linalg.h: At global scope:
./linalg/linalg.h: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]':
./linalg/linalg.h:1084: instantiated from 'void Matrix<T>::print(const std::string&) const [with T = float]'
dictLearn/mex/mexTrainDL.cpp:197: instantiated from here
./linalg/linalg.h:1084: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
./linalg/linalg.h: In instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]':
./linalg/linalg.h:1084: instantiated from 'void Matrix<T>::print(const std::string&) const [with T = float]'
dictLearn/mex/mexTrainDL.cpp:197: instantiated from here
./linalg/linalg.h:1084: error: explicit instantiation of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]' but no definition available
mex: compile of ' "dictLearn/mex/mexTrainDL.cpp"' failed.
The problem is not connected to the framework. Googling I have seen that I'm not the only one with this problem with matlab, but I don't know how to fix it. Thank you very much in advance for any help.
Mattia
UPDATE:
I've discovered that the error is produced by the following blocks of code
Block 1:
/// print the sparse matrix
template<typename T> inline void SpMatrix<T>::print(const string& name) const {
cerr << name << endl;
cerr << _m << " x " << _n << " , " << _nzmax << endl;
for (int i = 0; i<_n; ++i) {
for (int j = _pB[i]; j<_pE[i]; ++j) {
cerr << "(" <<_r[j] << "," << i << ") = " << _v[j] << endl;
}
}
};
Block 2
/// Print the matrix to std::cout
template <typename T> inline void Matrix<T>::print(const string& name) const {
std::cerr << name << std::endl;
std::cerr << _m << " x " << _n << std::endl;
for (int i = 0; i<_m; ++i) {
for (int j = 0; j<_n; ++j) {
printf("%10.5g ",static_cast<double>(_X[j*_m+i]));
// std::cerr << _X[j*_m+i] << " ";
}
printf("\n ");
//std::cerr << std::endl;
}
printf("\n ");
};
Block 3
template <typename T> void ShiftMatrix<T>::print(const string& name) const {
cerr << name << endl;
cerr << "Shift Matrix: " << _shifts << " shifts" << endl;
_inputmatrix->print(name);
};
And block 4
template <typename T> void DoubleRowMatrix<T>::print(const string& name) const {
cerr << name << endl;
cerr << "Double Row Matrix" << endl;
_inputmatrix->print(name);
};
and the error is always due to the first line of the above blocks, that is ...
cerr << name << endl;
Commenting the above line in the 4 blocks the compiling terminates successfully.
Does somebody know why this happens?
I solved this problem by adding the compile flag "-mmacosx-version-min=10.7" via the line
compile_flags=[compile_flags ' -mmacosx-version-min=10.7'];
in the SPAMS framework's compile.m immediately before the for block that calls mex.
This solution came from Trying to build muParser: error: explicit instantiation of 'std::basic_ostream but no definition available and Building libsigc++ fails (std::basic_ostream explicit instantiation) which appear to be the same problem with other packages.
I solved a similar problem by changing the MACOSX_DEPLOYMENT_TARGET='10.5' to '10.6' in mexopts.sh.

using the find function from algorithm on vector

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