starting to learn classes in c++ and i came across a simple board game... but i got this insane amount of error that i cant solve.
if i shouldn't post this kind of question here, please advise me.
Board.h:
#include<vector>
using namespace std;
class Board{
int largura;
int altura;
public:
Board(int x,int y) : largura(x), altura(y) {}
vector<vector<int> > mat();
void printa();
};
Board.cpp:
#include "Board.h"
#include <vector>
#include <iostream>
using namespace std;
vector<vector<int> > Board::mat() {
vector<vector<int> > v(altura, vector<int>(largura,1));
return v;
}
void Board::printa() {
auto matriz = mat();
vector<int> vec(largura,0);
for(;;) {
for (auto i:vec) {
for (auto j:vec) {
cout << matriz[i,j];
}
cout << "\n";
}
}
}
main.cpp:
#include<iostream>
#include "Board.h"
#include <vector>
using namespace std;
int main(){
Board tela(5, 5);
tela.mat();
tela.printa();
return 0;
}
the error:
[Rafael#localhost untitled]$ g++ -std=c++17 main.cpp Board.cpp -o board
Board.cpp: In member function ‘void Board::printa()’:
Board.cpp:22:22: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’)
cout << matriz[i,j];
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:108:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(__ostream_type& (*__pf)(__ostream_type&))
^~~~~~~~
/usr/include/c++/6.3.1/ostream:108:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/include/c++/6.3.1/ostream:117:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
operator<<(__ios_type& (*__pf)(__ios_type&))
^~~~~~~~
/usr/include/c++/6.3.1/ostream:117:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
/usr/include/c++/6.3.1/ostream:127:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(ios_base& (*__pf) (ios_base&))
^~~~~~~~
/usr/include/c++/6.3.1/ostream:127:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘std::ios_base& (*)(std::ios_base&)’
/usr/include/c++/6.3.1/ostream:166:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long __n)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:166:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘long int’
/usr/include/c++/6.3.1/ostream:170:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long __n)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:170:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘long unsigned int’
/usr/include/c++/6.3.1/ostream:174:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(bool __n)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:174:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘bool’
In file included from /usr/include/c++/6.3.1/ostream:638:0,
from /usr/include/c++/6.3.1/iostream:39,
from Board.cpp:7:
/usr/include/c++/6.3.1/bits/ostream.tcc:91:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6.3.1/bits/ostream.tcc:91:5: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘short int’
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:181:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned short __n)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:181:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘short unsigned int’
In file included from /usr/include/c++/6.3.1/ostream:638:0,
from /usr/include/c++/6.3.1/iostream:39,
from Board.cpp:7:
/usr/include/c++/6.3.1/bits/ostream.tcc:105:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6.3.1/bits/ostream.tcc:105:5: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘int’
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:192:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned int __n)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:192:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘unsigned int’
/usr/include/c++/6.3.1/ostream:201:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long long __n)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:201:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘long long int’
/usr/include/c++/6.3.1/ostream:205:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long long __n)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:205:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘long long unsigned int’
/usr/include/c++/6.3.1/ostream:220:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(double __f)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:220:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘double’
/usr/include/c++/6.3.1/ostream:224:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(float __f)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:224:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘float’
/usr/include/c++/6.3.1/ostream:232:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long double __f)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:232:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘long double’
/usr/include/c++/6.3.1/ostream:245:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(const void* __p)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:245:7: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘const void*’
In file included from /usr/include/c++/6.3.1/ostream:638:0,
from /usr/include/c++/6.3.1/iostream:39,
from Board.cpp:7:
/usr/include/c++/6.3.1/bits/ostream.tcc:119:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
basic_ostream<_CharT, _Traits>::
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6.3.1/bits/ostream.tcc:119:5: note: no known conversion for argument 1 from ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ to ‘std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’
In file included from /usr/include/c++/6.3.1/string:52:0,
from /usr/include/c++/6.3.1/bits/locale_classes.h:40,
from /usr/include/c++/6.3.1/bits/ios_base.h:41,
from /usr/include/c++/6.3.1/ios:42,
from /usr/include/c++/6.3.1/ostream:38,
from /usr/include/c++/6.3.1/iostream:39,
from Board.cpp:7:
/usr/include/c++/6.3.1/bits/basic_string.h:5325:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator<<(basic_ostream<_CharT, _Traits>& __os,
^~~~~~~~
/usr/include/c++/6.3.1/bits/basic_string.h:5325:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/bits/ios_base.h:46:0,
from /usr/include/c++/6.3.1/ios:42,
from /usr/include/c++/6.3.1/ostream:38,
from /usr/include/c++/6.3.1/iostream:39,
from Board.cpp:7:
/usr/include/c++/6.3.1/system_error:209:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::error_code&)
operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
^~~~~~~~
/usr/include/c++/6.3.1/system_error:209:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘const std::error_code&’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:497:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:497:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘std::vector<int>’)
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:502:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:502:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘char’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:508:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
operator<<(basic_ostream<char, _Traits>& __out, char __c)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:508:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘char’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:514:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:514:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘signed char’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:519:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:519:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘unsigned char’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:539:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:539:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: mismatched types ‘const _CharT*’ and ‘std::vector<int>’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/ostream:638:0,
from /usr/include/c++/6.3.1/iostream:39,
from Board.cpp:7:
/usr/include/c++/6.3.1/bits/ostream.tcc:321:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
^~~~~~~~
/usr/include/c++/6.3.1/bits/ostream.tcc:321:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘const char*’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:556:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:556:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘const char*’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:569:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:569:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘const signed char*’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:574:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:574:5: note: template argument deduction/substitution failed:
Board.cpp:22:35: note: cannot convert ‘matriz.std::vector<_Tp, _Alloc>::operator[]<std::vector<int>, std::allocator<std::vector<int> > >(((void)0, ((std::vector<std::vector<int> >::size_type)j)))’ (type ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> > >::value_type {aka std::vector<int>}’) to type ‘const unsigned char*’
cout << matriz[i,j];
^
In file included from /usr/include/c++/6.3.1/iostream:39:0,
from Board.cpp:7:
/usr/include/c++/6.3.1/ostream:628:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::vector<int>] <near match>
operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
^~~~~~~~
/usr/include/c++/6.3.1/ostream:628:5: note: conversion of argument 1 would be ill-formed:
Board.cpp:22:35: error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’
cout << matriz[i,j];
[i,j] is a trap. It's the same thing as [j]. What you want is matriz[i][j];, not matriz[i,j].
(You should also avoid using directives in header files, but that's purely cosmetic. Your problem is the [i,j] part.)
Related
For my research study, I need to fit some Supernovae Light Curves (LC). For this purpose, there are some templates available to fit the SNe lightcurves. One such LC template fitter is the snfit-2.4.2 . While building 1it from the source I'm getting some errors, which is described below:
salt2extinction.cc:132:10: error: no match for 'operator<<' (operand
types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'})
132 | cerr << message << endl;
| ~~~~ ^~ ~~~~~~~
| | |
| | std::stringstream {aka std::__cxx11::basic_stringstream<char>}
| std::ostream {aka std::basic_ostream<char>}
salt2extinction.cc:132:10: note: candidate: 'operator<<(int, int)' <built-in>
132 | cerr << message << endl;
| ~~~~~^~~~~~~~~~
salt2extinction.cc:132:10: note: no known conversion for argument 2 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'int'
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:108:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
108 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ^~~~~~~~
/usr/include/c++/9/ostream:108:36: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
108 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/ostream:117:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]'
117 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ^~~~~~~~
/usr/include/c++/9/ostream:117:32: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
117 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/9/ostream:127:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
127 | operator<<(ios_base& (*__pf) (ios_base&))
| ^~~~~~~~
/usr/include/c++/9/ostream:127:30: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'std::ios_base& (*)(std::ios_base&)'
127 | operator<<(ios_base& (*__pf) (ios_base&))
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/9/ostream:166:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
166 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/9/ostream:166:23: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'long int'
166 | operator<<(long __n)
| ~~~~~^~~
/usr/include/c++/9/ostream:170:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
170 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/9/ostream:170:32: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'long unsigned int'
170 | operator<<(unsigned long __n)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/9/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
174 | operator<<(bool __n)
| ^~~~~~~~
/usr/include/c++/9/ostream:174:23: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'bool'
174 | operator<<(bool __n)
| ~~~~~^~~
In file included from /usr/include/c++/9/ostream:702,
from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/bits/ostream.tcc:91:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
91 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/ostream.tcc:92:22: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'short int'
92 | operator<<(short __n)
| ~~~~~~^~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:181:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
181 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/9/ostream:181:33: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'short unsigned int'
181 | operator<<(unsigned short __n)
| ~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/ostream:702,
from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/bits/ostream.tcc:105:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
105 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/ostream.tcc:106:20: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'int'
106 | operator<<(int __n)
| ~~~~^~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:192:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
192 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/9/ostream:192:31: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'unsigned int'
192 | operator<<(unsigned int __n)
| ~~~~~~~~~~~~~^~~
/usr/include/c++/9/ostream:201:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
201 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/9/ostream:201:28: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'long long int'
201 | operator<<(long long __n)
| ~~~~~~~~~~^~~
/usr/include/c++/9/ostream:205:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
205 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/9/ostream:205:37: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'long long unsigned int'
205 | operator<<(unsigned long long __n)
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/ostream:220:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
220 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/9/ostream:220:25: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'double'
220 | operator<<(double __f)
| ~~~~~~~^~~
/usr/include/c++/9/ostream:224:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
224 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/9/ostream:224:24: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'float'
224 | operator<<(float __f)
| ~~~~~~^~~
/usr/include/c++/9/ostream:232:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
232 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/9/ostream:232:30: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'long double'
232 | operator<<(long double __f)
| ~~~~~~~~~~~~^~~
/usr/include/c++/9/ostream:245:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]'
245 | operator<<(const void* __p)
| ^~~~~~~~
/usr/include/c++/9/ostream:245:30: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'const void*'
245 | operator<<(const void* __p)
| ~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/ostream:702,
from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/bits/ostream.tcc:119:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]'
119 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/ostream.tcc:120:34: note: no known conversion for argument 1 from 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} to 'std::basic_ostream<char>::__streambuf_type*' {aka 'std::basic_streambuf<char>*'}
120 | operator<<(__streambuf_type* __sbin)
| ~~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/9/string:55,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/bits/basic_string.h:6416:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
6416 | operator<<(basic_ostream<_CharT, _Traits>& __os,
| ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6416:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/bits/ios_base.h:46,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/system_error:217:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::error_code&)'
217 | operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
| ^~~~~~~~
/usr/include/c++/9/system_error:217:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'const std::error_code&'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:506:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)'
506 | operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
| ^~~~~~~~
/usr/include/c++/9/ostream:506:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: deduced conflicting types for parameter '_CharT' ('char' and 'std::__cxx11::basic_stringstream<char>')
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:511:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)'
511 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/9/ostream:511:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'char'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:517:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)'
517 | operator<<(basic_ostream<char, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/9/ostream:517:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'char'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:523:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)'
523 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
| ^~~~~~~~
/usr/include/c++/9/ostream:523:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'signed char'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:528:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)'
528 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
| ^~~~~~~~
/usr/include/c++/9/ostream:528:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'unsigned char'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:548:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)'
548 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
| ^~~~~~~~
/usr/include/c++/9/ostream:548:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: mismatched types 'const _CharT*' and 'std::__cxx11::basic_stringstream<char>'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/ostream:702,
from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/bits/ostream.tcc:321:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)'
321 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
| ^~~~~~~~
/usr/include/c++/9/bits/ostream.tcc:321:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'const char*'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:565:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)'
565 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
| ^~~~~~~~
/usr/include/c++/9/ostream:565:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'const char*'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:578:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)'
578 | operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
| ^~~~~~~~
/usr/include/c++/9/ostream:578:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'const signed char*'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:583:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)'
583 | operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
| ^~~~~~~~
/usr/include/c++/9/ostream:583:5: note: template argument deduction/substitution failed:
salt2extinction.cc:132:13: note: cannot convert 'message' (type 'std::stringstream' {aka 'std::__cxx11::basic_stringstream<char>'}) to type 'const unsigned char*'
132 | cerr << message << endl;
| ^~~~~~~
In file included from /usr/include/c++/9/iostream:39,
from salt2extinction.cc:1:
/usr/include/c++/9/ostream:691:5: note: candidate: 'template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&)'
691 | operator<<(_Ostream&& __os, const _Tp& __x)
| ^~~~~~~~
/usr/include/c++/9/ostream:691:5: note: template argument deduction/substitution failed:
/usr/include/c++/9/ostream: In substitution of 'template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&) [with _Ostream = std::basic_ostream<char>&; _Tp = std::__cxx11::basic_stringstream<char>]':
salt2extinction.cc:132:13: required from here
/usr/include/c++/9/ostream:691:5: error: no type named 'type' in 'struct std::enable_if<false, std::basic_ostream<char>&>'
make[2]: *** [Makefile:619: salt2extinction.lo] Error 1
make[2]: Leaving directory '/usr/local/salt/build/snfit-2.4.2/src'
make[1]: *** [Makefile:305: all-recursive] Error 1
make[1]: Leaving directory '/usr/local/salt/build/snfit-2.4.2'
make: *** [Makefile:236: all] Error 2
The source file to build snfit-2.4.2 canbe downloaded from:
http://supernovae.in2p3.fr/salt/lib/exe/fetch.php?media=jla-installation.sh
I have tried to build this on three separate machines:
my own machine with :
AMD A8 7650 processor
Zorin 20.04 OS
My workstation #1 with:
Intel Xeon Octacore
Ubuntu 18.04.2
My workstation #2 with:
Intel Xeon Octacore
Ubuntu 20.04.2
In all these machines I'm getting the same problem.
I don't have much experience in C++.
Therefore, I'm not quite able to make sense of the issue to begin with.
The simple fix is change the code to:
stringstream message;
message << "ERROR Salt2ExtinctionLaw::Read unknown version " << version;
cerr << message.str() << endl;
Working off Chris's answer in this post How to print out the contents of a vector? I am trying to overload ostream << to print a vector vectors. Here's what I'm reading in from a file, where each line becomes a vector:
1, 2, 3
4, 4, 4, 4, 4
7, 7
41, 52, 632
So the structure looks something like
v[0] = [1, 2, 3]
and so on.
I thought Chris's solution should apply perfectly to this situation, and it certainly works for a 1d vector, but I'm trying to understand why it doesn't work for a 2d vector. The code's below:
template <typename T>
std::ostream& operator << (std::ostream& out, const std::vector<T>& v){
if(! v.empty()){
std::cout<< '[';
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
std::cout<< ']' << std::endl;
}
else{
std::cout << "[ ]" << std::endl;
}
}
I'm thinking I need to replace the function in std::ostream_iterator to be << since that is what I am overriding in the first place, but I have tried << and ostream::<< and std:: << and these all yield compile-time errors. What would be the proper way to do this?
If I try to run the code above as is on a vector of vectors of ints, I have the following compile-time error:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h: In instantiation of ‘std::ostream_iterator<_Tp, _CharT, _Traits>& std::ostream_iterator<_Tp, _CharT, _Traits>::operator=(const _Tp&) [with _Tp = std::vector<int>; _CharT = char; _Traits = std::char_traits<char>]’:
/usr/include/c++/4.9/bits/stl_algobase.h:336:18: required from ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = const std::vector<int>*; _OI = std::ostream_iterator<std::vector<int>, char, std::char_traits<char> >]’
/usr/include/c++/4.9/bits/stl_algobase.h:396:70: required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const std::vector<int>*; _OI = std::ostream_iterator<std::vector<int>, char, std::char_traits<char> >]’
/usr/include/c++/4.9/bits/stl_algobase.h:434:38: required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const std::vector<int>*, std::vector<std::vector<int> > >; _OI = std::ostream_iterator<std::vector<int>, char, std::char_traits<char> >]’
/usr/include/c++/4.9/bits/stl_algobase.h:466:17: required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const std::vector<int>*, std::vector<std::vector<int> > >; _OI = std::ostream_iterator<std::vector<int>, char, std::char_traits<char> >]’
ctest.cpp:15:75: required from ‘std::ostream& operator<<(std::ostream&, const std::vector<T>&) [with T = std::vector<int>; std::ostream = std::basic_ostream<char>]’
ctest.cpp:70:18: required from here
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: error: no match for ‘operator<<’ (operand types are ‘std::ostream_iterator<std::vector<int>, char, std::char_traits<char> >::ostream_type {aka std::basic_ostream<char>}’ and ‘const std::vector<int>’)
*_M_stream << __value;
^
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: candidates are:
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:108:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(__ostream_type& (*__pf)(__ostream_type&))
^
/usr/include/c++/4.9/ostream:108:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/include/c++/4.9/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
operator<<(__ios_type& (*__pf)(__ios_type&))
^
/usr/include/c++/4.9/ostream:117:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
/usr/include/c++/4.9/ostream:127:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(ios_base& (*__pf) (ios_base&))
^
/usr/include/c++/4.9/ostream:127:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘std::ios_base& (*)(std::ios_base&)’
/usr/include/c++/4.9/ostream:166:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long __n)
^
/usr/include/c++/4.9/ostream:166:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘long int’
/usr/include/c++/4.9/ostream:170:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long __n)
^
/usr/include/c++/4.9/ostream:170:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘long unsigned int’
/usr/include/c++/4.9/ostream:174:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(bool __n)
^
/usr/include/c++/4.9/ostream:174:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘bool’
In file included from /usr/include/c++/4.9/ostream:612:0,
from /usr/include/c++/4.9/iostream:39,
from ctest.cpp:1:
/usr/include/c++/4.9/bits/ostream.tcc:91:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.9/bits/ostream.tcc:91:5: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘short int’
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:181:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned short __n)
^
/usr/include/c++/4.9/ostream:181:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘short unsigned int’
In file included from /usr/include/c++/4.9/ostream:612:0,
from /usr/include/c++/4.9/iostream:39,
from ctest.cpp:1:
/usr/include/c++/4.9/bits/ostream.tcc:105:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.9/bits/ostream.tcc:105:5: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘int’
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:192:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned int __n)
^
/usr/include/c++/4.9/ostream:192:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘unsigned int’
/usr/include/c++/4.9/ostream:201:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long long __n)
^
/usr/include/c++/4.9/ostream:201:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘long long int’
/usr/include/c++/4.9/ostream:205:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long long __n)
^
/usr/include/c++/4.9/ostream:205:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘long long unsigned int’
/usr/include/c++/4.9/ostream:220:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(double __f)
^
/usr/include/c++/4.9/ostream:220:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘double’
/usr/include/c++/4.9/ostream:224:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(float __f)
^
/usr/include/c++/4.9/ostream:224:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘float’
/usr/include/c++/4.9/ostream:232:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long double __f)
^
/usr/include/c++/4.9/ostream:232:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘long double’
/usr/include/c++/4.9/ostream:245:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(const void* __p)
^
/usr/include/c++/4.9/ostream:245:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘const void*’
In file included from /usr/include/c++/4.9/ostream:612:0,
from /usr/include/c++/4.9/iostream:39,
from ctest.cpp:1:
/usr/include/c++/4.9/bits/ostream.tcc:119:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.9/bits/ostream.tcc:119:5: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’
In file included from /usr/include/c++/4.9/string:52:0,
from /usr/include/c++/4.9/bits/locale_classes.h:40,
from /usr/include/c++/4.9/bits/ios_base.h:41,
from /usr/include/c++/4.9/ios:42,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from ctest.cpp:1:
/usr/include/c++/4.9/bits/basic_string.h:2772:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/include/c++/4.9/bits/basic_string.h:2772:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: ‘const std::vector<int>’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:471:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
^
/usr/include/c++/4.9/ostream:471:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘std::vector<int>’)
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:476:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
^
/usr/include/c++/4.9/ostream:476:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘char’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:482:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
operator<<(basic_ostream<char, _Traits>& __out, char __c)
^
/usr/include/c++/4.9/ostream:482:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘char’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:488:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
^
/usr/include/c++/4.9/ostream:488:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘signed char’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:493:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
^
/usr/include/c++/4.9/ostream:493:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘unsigned char’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:513:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
^
/usr/include/c++/4.9/ostream:513:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: mismatched types ‘const _CharT*’ and ‘std::vector<int>’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/ostream:612:0,
from /usr/include/c++/4.9/iostream:39,
from ctest.cpp:1:
/usr/include/c++/4.9/bits/ostream.tcc:321:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
^
/usr/include/c++/4.9/bits/ostream.tcc:321:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘const char*’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:530:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
^
/usr/include/c++/4.9/ostream:530:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘const char*’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:543:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
^
/usr/include/c++/4.9/ostream:543:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘const signed char*’
*_M_stream << __value;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from ctest.cpp:1:
/usr/include/c++/4.9/ostream:548:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
^
/usr/include/c++/4.9/ostream:548:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.9/iterator:66:0,
from ctest.cpp:6:
/usr/include/c++/4.9/bits/stream_iterator.h:198:13: note: cannot convert ‘__value’ (type ‘const std::vector<int>’) to type ‘const unsigned char*’
*_M_stream << __value;
^
And this is the full file:
template <typename T>
std::ostream& operator << (std::ostream& out, const std::vector<T>& v){
if(! v.empty()){
std::cout<< '[';
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " "));
std::cout<< ']' << std::endl;
}
else{
std::cout << "[ ]" << std::endl;
}
}
int main()
{
std::ifstream infile("filetest.txt");
std::string output;
std::string line;
std::vector<std::vector<int> > vec;
while(std::getline(infile, line))
{
std::vector<int> subvec;
int i;
std::istringstream iss(line);
while(iss >> i)
{
subvec.push_back(i);
if(iss.peek()==','|| iss.peek()== ' ')
iss.ignore();
}
std::cout << subvec;
vec.push_back(subvec);
}
std::cout << vec;
}
It depends heavily upon how you want your output formatted. You can just use the operator as-is, and it'll work (though you may or may not like the formatting):
#include <vector>
using std::vector;
#include <iostream>
using std::ostream;
template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
out << "[";
size_t last = v.size() - 1;
for (size_t i = 0; i < v.size(); ++i) {
out << v[i];
if (i != last)
out << ", ";
}
out << "]";
return out;
}
int main() {
std::vector<std::vector<int> > x { { 1, 2, 3 }, { 4, 5, 6 } };
std::cout << x;
}
Produces:
[[1, 2, 3], [4, 5, 6]]
Things only get more difficult if you need/want to change the formatting between one instance and another, such as having commas between the numbers, and new-lines between the rows. This is somewhat non-trivial to solve well, but I'll leave it at this for now, since it's not at all clear you really even want that.
This idea uses std::enable_if to iterate through members of what we choose to define as is_container. I wrote the code more out of curiosity than out of practicality though.
#include <iostream>
#include <type_traits>
#include <vector>
// by default you declare that no type is a container
template<typename T>
struct is_container {
static constexpr bool value = false;
};
// then you specify which types are actually containers.. I'm just declaring
// std::vector<T, A>, but you could make a similar declaration for list, array,
// and so on.
template<typename T, typename Allocator>
struct is_container<std::vector<T, Allocator> > {
static constexpr bool value = true;
};
// then you enable a print function to print all elements in a container (you
// can modify the actual formatting to your liking)
template<typename T>
typename std::enable_if<
is_container<T>::value,
std::ostream& >::type
inline operator<<(std::ostream& os, const T& container) {
const auto N = container.size();
std::size_t current = 0;
os << "[";
for(const auto & item : container) {
const char* separator = current++ == N - 1 ? "" : ", ";
os << item << separator;
}
os << "]";
return os;
}
// then the code will work for any level of nesting
int main() {
int scalar = 1;
std::cout << "Scalar: " << scalar << std::endl;
std::vector<int> vector {1, 2, 3, 4};
std::cout << "Vector: " << vector << std::endl;
std::vector< std::vector<int> > vvector {
{1, 2, 3, 4},
{5, 6, 7},
{8, 9, 10, 11, 12}
};
std::cout << "Vector<Vector>: " << vvector << std::endl;
std::vector< std::vector< std::vector<int> > > vvvector {
{
{1, 2, 3, 4},
{5, 6, 7},
{8, 9, 10, 11, 12}
},
{
{-1, -2, -3, -4},
{-5, -6, -7},
{-8, -9, -10}
}
};
std::cout << "Vector<Vector<Vector>>: " << vvvector << std::endl;
// you get the idea...
return 0;
}
Sample run:
$ g++ example.cpp -std=c++14 -Wall -Wextra -O3
$ ./a.out
Scalar: 1
Vector: [1, 2, 3, 4]
Vector<Vector>: [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10, 11, 12]]
Vector<Vector<Vector>>: [[[1, 2, 3, 4], [5, 6, 7], [8, 9, 10, 11, 12]], [[-1, -2, -3, -4], [-5, -6, -7], [-8, -9, -10]]]
I have simple(not simple) question: Is any possibility that overloaded operator+ will be working not as we want when we won't use assignment overloaded operator?
Example:
object a, b, c;
//Here is some code where I add some numbers to object a and b;
c=a+b;
cout << c;
And the thing is: when I'm using overloaded assingment operator, everything is fine. But without this, elements which are in c gets some random numbers. Why?
And another question: why I can't do something like that with overloaded << and + operators:
cout << a+b;
EDIT: Here is code:
#include <iostream>
#include <cstdio>
using namespace std;
class List;
class element{
private:
int number;
element* next;
friend class List;
friend ostream & operator<<(ostream &, List &);
public:
element(int data){
number=data;
}
int getData(){
return number;
}
};
class List{
private:
element* head;
int size;
friend ostream & operator<<(ostream &, List &);
public:
List(){
head=NULL;
size=0;
}
List(const List &lista){
//cout << "wyw" << endl;
//fflush(stdout);
if (lista.size==0){
size=0;
head=NULL;
}
else
{
size=0;
head=NULL;
element* tmp=lista.head;
while(tmp!=NULL){
cout << tmp->number << " ";
fflush(stdout);
this->addToList(tmp->number);
tmp=tmp->next;
}
}
}
~List(){
if (head!=NULL){
element* tmp=head;
element *temp;
while(tmp!=NULL){
temp=tmp->next;
delete tmp;
tmp=temp;
}
head=NULL;
}
}
void addToList(int data){
element* newNode=new element(data);
newNode->next=NULL;
element *tmp=head;
if (tmp!=NULL){
while(tmp->next!=NULL){
tmp=tmp->next;
}
tmp->next=newNode;
}
else{
head=newNode;
}
size++;
}
List& operator=(const List& lista){
if (&lista==this) return *this;
if (this->head!=NULL){
element* tmp=head;
element *temp;
while(tmp!=NULL){
temp=tmp->next;
delete tmp;
tmp=temp;
}
head=NULL;
}
if (lista.size==0){
size=0;
head=NULL;
}
else
{
size=0;
head=NULL;
element* tmp=lista.head;
while(tmp!=NULL){
this->addToList(tmp->number);
tmp=tmp->next;
}
}
return *this;
}
List operator+(const List &lista){
List newList;
element *tmp=this->head;
while (tmp!=NULL){
newList.addToList(tmp->number);
tmp=tmp->next;
}
tmp=lista.head;
while (tmp!=NULL){
newList.addToList(tmp->number);
tmp=tmp->next;
}
return newList;
}
};
istream & operator>>(istream &str, List &lists){
int data;
str >> data;
lists.addToList(data);
return str;
}
ostream & operator<<(ostream &str, List &lists){
element*tmp=lists.head;
if (tmp==NULL){
str << "List is empty" << endl;
}
else{
while(tmp!=NULL){
str << tmp->number << "--";
tmp=tmp->next;
}
str << "NULL" << endl << "Size of lsit: " << lists.size << endl;
}
return str;
}
int main(){
List lista;
cin >> lista;
cin >> lista;
List list2=lista;
cout << lista;
cout << list2;
List c;
//cout << list2+lista; CANT DO THAT, WHY?
c=list2+lista;
cout << c;
return 0;
}
#DrewDormann Here is error:
lista.cpp: In function ‘int main()’:
lista.cpp:167:7: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘List’)
cout << lista+list2;
^
lista.cpp:167:7: note: candidates are:
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:108:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(__ostream_type& (*__pf)(__ostream_type&))
^
/usr/include/c++/4.8/ostream:108:7: note: no known conversion for argument 1 from ‘List’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/include/c++/4.8/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
operator<<(__ios_type& (*__pf)(__ios_type&))
^
/usr/include/c++/4.8/ostream:117:7: note: no known conversion for argument 1 from ‘List’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
/usr/include/c++/4.8/ostream:127:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(ios_base& (*__pf) (ios_base&))
^
/usr/include/c++/4.8/ostream:127:7: note: no known conversion for argument 1 from ‘List’ to ‘std::ios_base& (*)(std::ios_base&)’
/usr/include/c++/4.8/ostream:166:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long __n)
^
/usr/include/c++/4.8/ostream:166:7: note: no known conversion for argument 1 from ‘List’ to ‘long int’
/usr/include/c++/4.8/ostream:170:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long __n)
^
/usr/include/c++/4.8/ostream:170:7: note: no known conversion for argument 1 from ‘List’ to ‘long unsigned int’
/usr/include/c++/4.8/ostream:174:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(bool __n)
^
/usr/include/c++/4.8/ostream:174:7: note: no known conversion for argument 1 from ‘List’ to ‘bool’
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from lista.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:91:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.8/bits/ostream.tcc:91:5: note: no known conversion for argument 1 from ‘List’ to ‘short int’
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:181:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned short __n)
^
/usr/include/c++/4.8/ostream:181:7: note: no known conversion for argument 1 from ‘List’ to ‘short unsigned int’
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from lista.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:105:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.8/bits/ostream.tcc:105:5: note: no known conversion for argument 1 from ‘List’ to ‘int’
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:192:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned int __n)
^
/usr/include/c++/4.8/ostream:192:7: note: no known conversion for argument 1 from ‘List’ to ‘unsigned int’
/usr/include/c++/4.8/ostream:201:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long long __n)
^
/usr/include/c++/4.8/ostream:201:7: note: no known conversion for argument 1 from ‘List’ to ‘long long int’
/usr/include/c++/4.8/ostream:205:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long long __n)
^
/usr/include/c++/4.8/ostream:205:7: note: no known conversion for argument 1 from ‘List’ to ‘long long unsigned int’
/usr/include/c++/4.8/ostream:220:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(double __f)
^
/usr/include/c++/4.8/ostream:220:7: note: no known conversion for argument 1 from ‘List’ to ‘double’
/usr/include/c++/4.8/ostream:224:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(float __f)
^
/usr/include/c++/4.8/ostream:224:7: note: no known conversion for argument 1 from ‘List’ to ‘float’
/usr/include/c++/4.8/ostream:232:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long double __f)
^
/usr/include/c++/4.8/ostream:232:7: note: no known conversion for argument 1 from ‘List’ to ‘long double’
/usr/include/c++/4.8/ostream:245:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(const void* __p)
^
/usr/include/c++/4.8/ostream:245:7: note: no known conversion for argument 1 from ‘List’ to ‘const void*’
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from lista.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:119:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.8/bits/ostream.tcc:119:5: note: no known conversion for argument 1 from ‘List’ to ‘std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’
lista.cpp:141:12: note: std::ostream& operator<<(std::ostream&, List&)
ostream & operator<<(ostream &str, List &lists){
^
lista.cpp:141:12: note: no known conversion for argument 2 from ‘List’ to ‘List&’
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:548:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
^
/usr/include/c++/4.8/ostream:548:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘const unsigned char*’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:543:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
^
/usr/include/c++/4.8/ostream:543:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘const signed char*’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:530:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
^
/usr/include/c++/4.8/ostream:530:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘const char*’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from lista.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
^
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘const char*’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:513:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
^
/usr/include/c++/4.8/ostream:513:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: mismatched types ‘const _CharT*’ and ‘List’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:493:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
^
/usr/include/c++/4.8/ostream:493:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘unsigned char’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:488:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
^
/usr/include/c++/4.8/ostream:488:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘signed char’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:482:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
operator<<(basic_ostream<char, _Traits>& __out, char __c)
^
/usr/include/c++/4.8/ostream:482:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘char’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:476:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
^
/usr/include/c++/4.8/ostream:476:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: cannot convert ‘List::operator+(const List&)((*(const List*)(& list2)))’ (type ‘List’) to type ‘char’
cout << lista+list2;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from lista.cpp:1:
/usr/include/c++/4.8/ostream:471:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
^
/usr/include/c++/4.8/ostream:471:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘List’)
cout << lista+list2;
^
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 lista.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template argument deduction/substitution failed:
lista.cpp:167:16: note: ‘List’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
cout << lista+list2;
I know that this is when i'm trying to use operaotr without overloading, but here problem is that operator << is overloaded.
Yes, it is possible.
For example: Imagine that both + and = operators also invert a number. If you invert twice - you get correct result. But if you invert it only once (e.g. using non-overloaded = operator) you get an unexpected result.
What is happening in your case - I have no idea. You provide not enough data for a more concrete and useful answer.
I am attempting to print out the numbers from 1 to 1000 in C++ without any control statements or conditionals. I have found this question + answer on SO, but I cannot compile it on Linux with gcc 4.8. Any ideas why this is not working?
This is the code I'm trying:
#include <iostream>
template<int N>
struct NumberGeneration{
static void out(std::ostream& os)
{
NumberGeneration<N-1>::out(os);
os << N << std::endl;
}
};
template<>
struct NumberGeneration<1>{
static void out(std::ostream& os)
{
os << 1 << std::endl;
}
};
int main(){
NumberGeneration<1000>::out(std::cout);
}
The error I get is this:
main2.cpp:9:34: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) instantiating ‘struct NumberGeneration<100>’
NumberGeneration<N-1>::out(os);
^
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:9:34: error: incomplete type ‘NumberGeneration<100>’ used in nested name specifier
main2.cpp:10:8: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char) [with _CharT = char; _Traits = std::char_traits<char>]’
os << N << std::endl;
^
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:10:8: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char) [with _Traits = std::char_traits<char>]’
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:10:8: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char) [with _Traits = std::char_traits<char>]’
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:10:8: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char) [with _Traits = std::char_traits<char>]’
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:10:13: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT) [with _CharT = char; _Traits = std::char_traits<char>]’
os << N << std::endl;
^
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:10:13: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>]’
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:10:13: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::endl(std::basic_ostream<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’
main2.cpp:9:34: recursively required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 999; std::ostream = std::basic_ostream<char>]’
main2.cpp:9:34: required from ‘static void NumberGeneration<N>::out(std::ostream&) [with int N = 1000; std::ostream = std::basic_ostream<char>]’
main2.cpp:21:28: required from here
main2.cpp:10:13: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘<unresolved overloaded function type>’)
main2.cpp:10:13: note: candidates are:
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:108:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(__ostream_type& (*__pf)(__ostream_type&))
^
/usr/include/c++/4.8/ostream:108:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/include/c++/4.8/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
operator<<(__ios_type& (*__pf)(__ios_type&))
^
/usr/include/c++/4.8/ostream:117:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
/usr/include/c++/4.8/ostream:127:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(ios_base& (*__pf) (ios_base&))
^
/usr/include/c++/4.8/ostream:127:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::ios_base& (*)(std::ios_base&)’
/usr/include/c++/4.8/ostream:166:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long __n)
^
/usr/include/c++/4.8/ostream:166:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long int’
/usr/include/c++/4.8/ostream:170:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long __n)
^
/usr/include/c++/4.8/ostream:170:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long unsigned int’
/usr/include/c++/4.8/ostream:174:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(bool __n)
^
/usr/include/c++/4.8/ostream:174:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘bool’
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from main2.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:91:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.8/bits/ostream.tcc:91:5: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘short int’
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:181:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned short __n)
^
/usr/include/c++/4.8/ostream:181:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘short unsigned int’
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from main2.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:105:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.8/bits/ostream.tcc:105:5: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘int’
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:192:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned int __n)
^
/usr/include/c++/4.8/ostream:192:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘unsigned int’
/usr/include/c++/4.8/ostream:201:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long long __n)
^
/usr/include/c++/4.8/ostream:201:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long long int’
/usr/include/c++/4.8/ostream:205:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(unsigned long long __n)
^
/usr/include/c++/4.8/ostream:205:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long long unsigned int’
/usr/include/c++/4.8/ostream:220:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(double __f)
^
/usr/include/c++/4.8/ostream:220:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘double’
/usr/include/c++/4.8/ostream:224:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(float __f)
^
/usr/include/c++/4.8/ostream:224:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘float’
/usr/include/c++/4.8/ostream:232:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(long double __f)
^
/usr/include/c++/4.8/ostream:232:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long double’
/usr/include/c++/4.8/ostream:245:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(const void* __p)
^
/usr/include/c++/4.8/ostream:245:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘const void*’
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from main2.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:119:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
basic_ostream<_CharT, _Traits>::
^
/usr/include/c++/4.8/bits/ostream.tcc:119:5: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:548:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
^
/usr/include/c++/4.8/ostream:548:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘const unsigned char*’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:543:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
^
/usr/include/c++/4.8/ostream:543:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘const signed char*’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:530:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
^
/usr/include/c++/4.8/ostream:530:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘const char*’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/ostream:609:0,
from /usr/include/c++/4.8/iostream:39,
from main2.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
^
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘const char*’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:513:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
^
/usr/include/c++/4.8/ostream:513:5: note: substitution of deduced template arguments resulted in errors seen above
/usr/include/c++/4.8/ostream:493:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
^
/usr/include/c++/4.8/ostream:493:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘unsigned char’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:488:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
^
/usr/include/c++/4.8/ostream:488:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘signed char’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:482:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
operator<<(basic_ostream<char, _Traits>& __out, char __c)
^
/usr/include/c++/4.8/ostream:482:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘char’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:476:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
^
/usr/include/c++/4.8/ostream:476:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘char’
os << N << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from main2.cpp:1:
/usr/include/c++/4.8/ostream:471:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
^
/usr/include/c++/4.8/ostream:471:5: note: substitution of deduced template arguments resulted in errors seen above
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 main2.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template argument deduction/substitution failed:
main2.cpp:10:13: note: couldn't deduce template parameter ‘_Alloc’
os << N << std::endl;
^
And when I increase template instantiation depth I get :
$ gcc -Wall -ftemplate-depth=1100 -omain2 main2.cpp
/tmp/ccI81cmF.o: In function `main':
main2.cpp:(.text+0x5): undefined reference to `std::cout'
/tmp/ccI81cmF.o: In function `__static_initialization_and_destruction_0(int, int)':
main2.cpp:(.text+0x38): undefined reference to `std::ios_base::Init::Init()'
main2.cpp:(.text+0x47): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccI81cmF.o: In function `NumberGeneration<1>::out(std::ostream&)':
main2.cpp:(.text._ZN16NumberGenerationILi1EE3outERSo[_ZN16NumberGenerationILi1EE3outERSo]+0x19): undefined reference to `std::ostream::operator<<(int)'
main2.cpp:(.text._ZN16NumberGenerationILi1EE3outERSo[_ZN16NumberGenerationILi1EE3outERSo]+0x1e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main2.cpp:(.text._ZN16NumberGenerationILi1EE3outERSo[_ZN16NumberGenerationILi1EE3outERSo]+0x26): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccI81cmF.o: In function `NumberGeneration<1000>::out(std::ostream&)':
main2.cpp:(.text._ZN16NumberGenerationILi1000EE3outERSo[_ZN16NumberGenerationILi1000EE3outERSo]+0x25): undefined reference to `std::ostream::operator<<(int)'
main2.cpp:(.text._ZN16NumberGenerationILi1000EE3outERSo[_ZN16NumberGenerationILi1000EE3outERSo]+0x2a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
main2.cpp:(.text._ZN16NumberGenerationILi1000EE3outERSo[_ZN16NumberGenerationILi1000EE3outERSo]+0x32): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
As state in the comment, you reach the template depth limit, and use the wrong compiler:
so use a C++ compiler as g++
And then you may pass this argument to increase depth limit -depth=1000
or you may instantiate intermediate template as
template struct NumberGeneration<500>;
or rewrite your template to not use a depth linear with N
something like the following
// index_sequence and make_index_sequence available in C++14, but not in C++11
template <std::size_t...> struct index_sequence {};
namespace detail
{
template <typename, typename> struct concat;
template <std::size_t... Is1, std::size_t... Is2>
struct concat<index_sequence<Is1...>, index_sequence<Is2...>> :
index_sequence<Is1..., (sizeof...(Is1) + Is2)...>
{
using type = index_sequence<Is1..., (sizeof...(Is1) + Is2)...>;
};
}
template <std::size_t N>
struct make_index_sequence :
detail::concat<typename make_index_sequence<N / 2>::type,
typename make_index_sequence<N - N / 2>::type>::type
{
using type = typename
detail::concat<typename make_index_sequence<N / 2>::type,
typename make_index_sequence<N - N / 2>::type>::type;
};
template <>
struct make_index_sequence<1u> : index_sequence<0u> {
using type = index_sequence<0u>;
};
template <>
struct make_index_sequence<0u> : index_sequence<> {
using type = index_sequence<>;
};
And then with variadic template:
template<int N>
struct NumberGeneration{
static void out(std::ostream& os)
{
out(make_index_sequence<N>(), os);
}
private:
template<std::size_t ...Is>
static void out(index_sequence<Is...>, std::ostream& os)
{
std::initializer_list<int>{ ((os << (1 + Is) << std::endl), void(), 0)...};
}
};
Live example
The big problem is that it is really bad C++. It has a 1000 deep template instantiation depth, and the C++11 standard only advises 900. What more, there is little to no need for something that deep to do such a simple task.
Most compilers have template instantiation depth modification flags that make it larger. That is, however, a patch over the problem. The right way to fix that code is to either not write it, or decrease the depth.
#include <iostream>
template<int Max, unsigned Count=Max>
struct NumberGeneration{
void operator()(std::ostream& os) const
{
NumberGeneration<Max, (Count+1)/2>()(os);
NumberGeneration<Max-(Count+1)/2, (Count)/2>()(os);
}
};
template<int Max>
struct NumberGeneration<Max, 1>{
void operator()(std::ostream& os) const
{
os << Max << std::endl;
}
};
// not required:
template<int Max>
struct NumberGeneration<Max, 0>{
void operator()(std::ostream& os) const
{}
};
int main(){
NumberGeneration<1000>()(std::cout);
}
This now has a recursive template instantiation depth of about 10 instead of 1000, and is nearly as simple as the original version. I simply replaced single recursion with divide-and-conquer.
In C++14, efficient lists of integers via std::integral_sequence exist, and allow the above kind of thing even easier.
I also made NumberGeneration<X> into a stateless invokable type instead of having a static void out() method.
I am trying to read a json file using boost::property_tree. I have been able to read the json file and get values of properties. Now, I am trying to iterate through all the properties within the property tree and print out all the key value pairs. I'm not sure how to exactly do this. I have tried using BOOST_FOREACH but I end up getting a compile error. How do I properly iterate through the properties in the property tree variable and get their respective keys and values?
#include <fstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <exception>
#include <string>
using namespace std;
int main(){
boost::property_tree::ptree pt;
boost::property_tree::read_json("./data.json", pt);
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt)
{
std::cout << v.first << ":" << v.second << std::endl;
}
std::cout<<pt.get<string>("name")<<std::endl;
std::cout <<"Done"<<std::endl;
return 1;
}
I get a compiler error on the line std::cout << v.first << ":" << v.second << std::endl;. I am compiling using g++ -o test test.c. The compile error is:
test.c: In function 'int main()':
test.c:20:42: error: no match for 'operator<<' in 'std::operator<< <std::char_traits<char> >((* & std::operator<< <char, std::char_traits<char>, std::allocator<char> >((* & std::cout), (* & v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::first))), ((const char*)":")) << v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second'
test.c:20:42: note: candidates are:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:106:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:106:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:115:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:115:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:125:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:125:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::ios_base& (*)(std::ios_base&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:164:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:164:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:168:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:168:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long unsigned int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:172:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:172:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'bool'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:93:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:93:5: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'short int'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:179:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:179:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'short unsigned int'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:107:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:107:5: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'int'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:190:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:190:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'unsigned int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:199:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:199:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long long int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:203:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:203:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long long unsigned int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:218:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:218:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'double'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:222:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:222:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'float'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:230:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:230:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long double'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:243:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:243:7: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'const void*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:121:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:121:5: note: no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/string:54:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/locale_classes.h:42,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:43,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ios:43,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:40,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/basic_string.h:2750:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/basic_string.h:2750:5: note: template argument deduction/substitution failed:
test.c:20:42: note: 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:469:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:469:5: note: template argument deduction/substitution failed:
test.c:20:42: note: deduced conflicting types for parameter '_CharT' ('char' and 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >')
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:474:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:474:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:480:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:480:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:486:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:486:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'signed char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:491:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:491:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'unsigned char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:511:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:511:5: note: template argument deduction/substitution failed:
test.c:20:42: note: mismatched types 'const _CharT*' and 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:323:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:323:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const char*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:528:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:528:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const char*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:541:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:541:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const signed char*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:546:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:546:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const unsigned char*'
In file included from /usr/include/boost/spirit/home/classic/utility/impl/chset/basic_chset.hpp:13:0,
from /usr/include/boost/spirit/home/classic/utility/chset.hpp:16,
from /usr/include/boost/spirit/home/classic/utility.hpp:26,
from /usr/include/boost/spirit/home/classic.hpp:29,
from /usr/include/boost/spirit/include/classic.hpp:11,
from /usr/include/boost/property_tree/detail/json_parser_read.hpp:18,
from /usr/include/boost/property_tree/json_parser.hpp:14,
from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bitset:1523:5: note: template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::bitset<_Nb>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bitset:1523:5: note: template argument deduction/substitution failed:
test.c:20:42: note: 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' is not derived from 'const std::bitset<_Nb>'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
from /usr/include/boost/property_tree/json_parser.hpp:15,
from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:78:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Resetiosflags)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:78:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Resetiosflags'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
from /usr/include/boost/property_tree/json_parser.hpp:15,
from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:108:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setiosflags)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:108:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setiosflags'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
from /usr/include/boost/property_tree/json_parser.hpp:15,
from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:142:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setbase)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:142:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setbase'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
from /usr/include/boost/property_tree/json_parser.hpp:15,
from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:177:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setfill<_CharT>)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:177:5: note: template argument deduction/substitution failed:
test.c:20:42: note: 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' is not derived from 'std::_Setfill<_CharT>'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
from /usr/include/boost/property_tree/json_parser.hpp:15,
from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:207:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setprecision)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:207:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setprecision'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
from /usr/include/boost/property_tree/json_parser.hpp:15,
from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:237:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setw)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:237:5: note: template argument deduction/substitution failed:
test.c:20:42: note: cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setw'
I named my file test.c instead of test.cpp, so that could have been an issue. But changing that did not fix the problem. I changed v.second to v.second.data() and it worked fine.