{"metadata":{"orig_nbformat":4,"language_info":{"codemirror_mode":"text/x-c++src","file_extension":".cpp","mimetype":"text/x-c++src","name":"c++","version":"11"},"kernelspec":{"name":"xcpp11","display_name":"C++11","language":"C++11"}},"nbformat_minor":5,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Friendship","metadata":{},"id":"e04e0b83-753f-4a58-bce3-3746e7c69650"},{"cell_type":"markdown","source":"* In many situations we tend to make the data members of our classes **private** (or protected in the case of inheritance). \n* If we do so, then no objects of other classes or free-functions have access to them. Not even other objects of the same class.\n* Sometimes this is too restrictive, though. We might need to provide direct access to our members for selected **friends**.\n\n* A typical example is, when we want to overload the ```<<``` operator, to be able to place our object into an output stream.","metadata":{},"id":"6c224ee8-f4c0-495c-8261-6d2c17f845a6"},{"cell_type":"markdown","source":"***\nLet us create a simpe demo class","metadata":{},"id":"ff1a3263-e349-4840-af2f-ad90fde352ac"},{"cell_type":"code","source":"class myTuple {\n\n int fir;\n int sec;\n\npublic:\n myTuple( int fir, int sec ) : fir(fir), sec(sec) {};\n\n};","metadata":{"trusted":true},"execution_count":1,"outputs":[],"id":"cebe299d-3bcc-4a57-af69-8aed41401244"},{"cell_type":"markdown","source":"and try to test-run it","metadata":{},"id":"97622c4c-2eba-47cd-8dbb-c2fe9963dbc3"},{"cell_type":"code","source":"#include <iostream>\n\nint main() {\n\n myTuple obj( 3, 5 );\n\n std::cout << \"Pair is: \" << obj << std::endl;\n}\n\nmain();","metadata":{"trusted":true},"execution_count":2,"outputs":[{"name":"stderr","text":"input_line_9:3:28: error: invalid operands to binary expression ('basic_ostream<char, std::char_traits<char> >' and '__cling_N52::myTuple')\n std::cout << \"Pair is: \" << obj << std::endl;\n ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:245:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const void *' for 1st argument; take the address of the argument with &\n operator<<(const void* __p)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/system_error:217:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const std::error_code' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:108:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ostream_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ostream_type &)' (aka 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &)') for 1st argument\n operator<<(__ostream_type& (*__pf)(__ostream_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:117:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ios_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ios_type &)' (aka 'basic_ios<char, std::char_traits<char> > &(*)(basic_ios<char, std::char_traits<char> > &)') for 1st argument\n operator<<(__ios_type& (*__pf)(__ios_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:127:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument\n operator<<(ios_base& (*__pf) (ios_base&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:166:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long' for 1st argument\n operator<<(long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:170:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long' for 1st argument\n operator<<(unsigned long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:174:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'bool' for 1st argument\n operator<<(bool __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:178:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'short' for 1st argument\n operator<<(short __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:181:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned short' for 1st argument\n operator<<(unsigned short __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:189:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'int' for 1st argument\n operator<<(int __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:192:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned int' for 1st argument\n operator<<(unsigned int __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:201:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long long' for 1st argument\n operator<<(long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:205:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long long' for 1st argument\n operator<<(unsigned long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:220:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'double' for 1st argument\n operator<<(double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:224:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'float' for 1st argument\n operator<<(float __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:232:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long double' for 1st argument\n operator<<(long double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:276:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__streambuf_type *' (aka 'basic_streambuf<char, std::char_traits<char> > *') for 1st argument\n operator<<(__streambuf_type* __sb);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:511:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:517:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:523:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'signed char' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, signed char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:528:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned char' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:565:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:578:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const signed char *' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:583:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const unsigned char *' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/ostream.tcc:321:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:506:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. '__cling_N52::myTuple')\n operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/basic_string.h:6419:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against '__cling_N52::myTuple'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:548:5: note: candidate template ignored: could not match 'const _CharT *' against '__cling_N52::myTuple'\n operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:691:5: note: candidate template ignored: requirement '__and_<__not_<is_lvalue_reference<basic_ostream<char> &> >, __is_convertible_to_basic_ostream<basic_ostream<char> &>, __is_insertable<__rvalue_ostream_type<basic_ostream<char> &>, const myTuple &> >::value' was not satisfied [with _Ostream = std::basic_ostream<char> &, _Tp = __cling_N52::myTuple]\n operator<<(_Ostream&& __os, const _Tp& __x)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/shared_ptr.h:66:5: note: candidate template ignored: could not match '__shared_ptr<type-parameter-0-2, _Lp>' against '__cling_N52::myTuple'\n operator<<(std::basic_ostream<_Ch, _Tr>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n _DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const typename _Dom::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const valarray<typename _Dom::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n_DEFINE_BINARY_OPERATOR(<<, __shift_left)\n^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray<type-parameter-0-0>' against '__cling_N52::myTuple'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const typename valarray<_Tp>::value_type& __t, \\\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}],"id":"7b80f338-bd48-4699-81aa-fbae245a3a04"},{"cell_type":"markdown","source":"Okay that obviously did not work. Problem is that ```<<``` does not know how to work with objects of type ```myTuple```.\n\n\n* We can fix this by implementing a version of ```<<``` that understands it. \n* Different from our overloading of ```[ ]``` for our ```VectorClass```, we do not do this on the object. Instead we need to overload the free-function that is ```<<```.","metadata":{},"id":"8b28c2a6-533e-478b-91e1-b63270121d6c"},{"cell_type":"code","source":"%%file myTuple.cpp\n\n#include <iostream>\n\nclass myTuple {\n\n int fir;\n int sec;\n\npublic:\n myTuple( int fir, int sec ) : fir(fir), sec(sec) {};\n\n};\n\nstd::ostream& operator << ( std::ostream &os, const myTuple& tup )\n{] for\n os << \"( \" << tup.fir << \" , \" << tup.sec << \" )\" << std::endl;\n \n // necessary for chaining:\n return os;\n}","metadata":{"trusted":true},"execution_count":2,"outputs":[{"name":"stdout","text":"Overwriting myTuple.cpp\n","output_type":"stream"}],"id":"8dfa7a1c-28d8-4de1-ae19-bdb2a6d3e48e"},{"cell_type":"code","source":"!g++ -Wall -Wextra -c myTuple.cpp","metadata":{"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"myTuple.cpp: In function ‘std::ostream& operator<<(std::ostream&, const myTuple&)’:\nmyTuple.cpp:15:2: error: expected primary-expression before ‘]’ token\n {] for\n ^\nmyTuple.cpp:14:62: warning: unused parameter ‘tup’ [-Wunused-parameter]\n std::ostream& operator << ( std::ostream &os, const myTuple& tup )\n ^~~\n","output_type":"stream"}],"id":"25e56a5e-6c64-4d77-9a81-5d808f2b63b3"},{"cell_type":"markdown","source":"* That was to be expected. The attributes ```fir``` and ```sec``` of ```myTuple``` are private.\n* However, we do not want to make them accessible to everyone, just for the sake of one special function/operator.\n* But, we can do so **selectively**, with the friend statement.","metadata":{},"id":"092b284c-9b78-4ea9-9b9a-f43cc5f32612"},{"cell_type":"code","source":"%%file myTuple.cpp\n\n#include <iostream>\n\nclass myTuple {\n\n int fir;\n int sec;\n\n friend std::ostream& operator << ( std::ostream&, const myTuple& );\n\npublic:\n myTuple( int fir, int sec ) : fir(fir), sec(sec) {};\n\n};\n\nstd::ostream& operator << ( std::ostream &os, const myTuple& tup )\n{\n os << \"( \" << tup.fir << \" , \" << tup.sec << \" )\" << std::endl;\n \n // necessary for chaining:\n return os;\n}\n\nint main() {\n\n myTuple obj( 3, 5 );\n\n std::cout << \"Pair is: \" << obj << std::endl;\n}","metadata":{"trusted":true},"execution_count":10,"outputs":[{"name":"stdout","text":"Overwriting myTuple.cpp\n","output_type":"stream"}],"id":"ff341d41-7aa2-4f87-92f2-e189dd448d68"},{"cell_type":"code","source":"!g++ -Wall -Wextra myTuple.cpp","metadata":{"trusted":true},"execution_count":11,"outputs":[],"id":"c8560f81-10ef-4203-b3f3-8046255be25a"},{"cell_type":"code","source":"!./a.out","metadata":{"trusted":true},"execution_count":12,"outputs":[{"name":"stdout","text":"Pair is: ( 3 , 5 )\n\n","output_type":"stream"}],"id":"6a5f1cb3-7891-4cb8-b8ce-d3f6aa996ecc"},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[],"id":"94e6f340-7a06-4c59-8889-5088e41712f2"}]}
{"metadata":{"orig_nbformat":4,"language_info":{"codemirror_mode":"text/x-c++src","file_extension":".cpp","mimetype":"text/x-c++src","name":"c++","version":"11"},"kernelspec":{"name":"xcpp11","display_name":"C++11","language":"C++11"}},"nbformat_minor":5,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Friendship","metadata":{},"id":"e04e0b83-753f-4a58-bce3-3746e7c69650"},{"cell_type":"markdown","source":"* In many situations we tend to make the data members of our classes **private** (or protected in the case of inheritance). \n* If we do so, then no objects of other classes or free-functions have access to them. Not even other objects of the same class.\n* Sometimes this is too restrictive, though. We might need to provide direct access to our members for selected **friends**.\n\n* A typical example is, when we want to overload the ```<<``` operator, to be able to place our object into an output stream.","metadata":{},"id":"6c224ee8-f4c0-495c-8261-6d2c17f845a6"},{"cell_type":"markdown","source":"***\nLet us create a simpe demo class","metadata":{},"id":"ff1a3263-e349-4840-af2f-ad90fde352ac"},{"cell_type":"code","source":"class myTuple {\n\n int fir;\n int sec;\n\npublic:\n myTuple( int fir, int sec ) : fir(fir), sec(sec) {};\n\n};","metadata":{"trusted":true},"execution_count":1,"outputs":[],"id":"cebe299d-3bcc-4a57-af69-8aed41401244"},{"cell_type":"markdown","source":"and try to test-run it","metadata":{},"id":"97622c4c-2eba-47cd-8dbb-c2fe9963dbc3"},{"cell_type":"code","source":"#include <iostream>\n\nint main() {\n\n myTuple obj( 3, 5 );\n\n std::cout << \"Pair is: \" << obj << std::endl;\n}\n\nmain();","metadata":{"trusted":true},"execution_count":2,"outputs":[{"name":"stderr","text":"input_line_9:3:28: error: invalid operands to binary expression ('basic_ostream<char, std::char_traits<char> >' and '__cling_N52::myTuple')\n std::cout << \"Pair is: \" << obj << std::endl;\n ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:245:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const void *' for 1st argument; take the address of the argument with &\n operator<<(const void* __p)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/system_error:217:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const std::error_code' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:108:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ostream_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ostream_type &)' (aka 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &)') for 1st argument\n operator<<(__ostream_type& (*__pf)(__ostream_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:117:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ios_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ios_type &)' (aka 'basic_ios<char, std::char_traits<char> > &(*)(basic_ios<char, std::char_traits<char> > &)') for 1st argument\n operator<<(__ios_type& (*__pf)(__ios_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:127:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument\n operator<<(ios_base& (*__pf) (ios_base&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:166:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long' for 1st argument\n operator<<(long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:170:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long' for 1st argument\n operator<<(unsigned long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:174:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'bool' for 1st argument\n operator<<(bool __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:178:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'short' for 1st argument\n operator<<(short __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:181:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned short' for 1st argument\n operator<<(unsigned short __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:189:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'int' for 1st argument\n operator<<(int __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:192:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned int' for 1st argument\n operator<<(unsigned int __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:201:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long long' for 1st argument\n operator<<(long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:205:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long long' for 1st argument\n operator<<(unsigned long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:220:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'double' for 1st argument\n operator<<(double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:224:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'float' for 1st argument\n operator<<(float __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:232:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long double' for 1st argument\n operator<<(long double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:276:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__streambuf_type *' (aka 'basic_streambuf<char, std::char_traits<char> > *') for 1st argument\n operator<<(__streambuf_type* __sb);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:511:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:517:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:523:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'signed char' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, signed char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:528:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned char' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:565:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:578:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const signed char *' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:583:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const unsigned char *' for 2nd argument\n operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/ostream.tcc:321:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:506:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. '__cling_N52::myTuple')\n operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/basic_string.h:6419:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against '__cling_N52::myTuple'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:548:5: note: candidate template ignored: could not match 'const _CharT *' against '__cling_N52::myTuple'\n operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:691:5: note: candidate template ignored: requirement '__and_<__not_<is_lvalue_reference<basic_ostream<char> &> >, __is_convertible_to_basic_ostream<basic_ostream<char> &>, __is_insertable<__rvalue_ostream_type<basic_ostream<char> &>, const myTuple &> >::value' was not satisfied [with _Ostream = std::basic_ostream<char> &, _Tp = __cling_N52::myTuple]\n operator<<(_Ostream&& __os, const _Tp& __x)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/shared_ptr.h:66:5: note: candidate template ignored: could not match '__shared_ptr<type-parameter-0-2, _Lp>' against '__cling_N52::myTuple'\n operator<<(std::basic_ostream<_Ch, _Tr>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n _DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const typename _Dom::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const valarray<typename _Dom::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n_DEFINE_BINARY_OPERATOR(<<, __shift_left)\n^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray<type-parameter-0-0>' against '__cling_N52::myTuple'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const typename valarray<_Tp>::value_type& __t, \\\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}],"id":"7b80f338-bd48-4699-81aa-fbae245a3a04"},{"cell_type":"markdown","source":"Okay that obviously did not work. Problem is that ```<<``` does not know how to work with objects of type ```myTuple```.\n\n\n* We can fix this by implementing a version of ```<<``` that understands it. \n* Different from our overloading of ```[ ]``` for our ```VectorClass```, we do not do this on the object. Instead we need to overload the free-function that is ```<<```.","metadata":{},"id":"8b28c2a6-533e-478b-91e1-b63270121d6c"},{"cell_type":"code","source":"%%file myTuple.cpp\n\n#include <iostream>\n\nclass myTuple {\n\n int fir;\n int sec;\n\npublic:\n myTuple( int fir, int sec ) : fir(fir), sec(sec) {};\n\n};\n\nstd::ostream& operator << ( std::ostream &os, const myTuple& tup )\n{\n os << \"( \" << tup.fir << \" , \" << tup.sec << \" )\";\n \n // necessary for chaining:\n return os;\n}","metadata":{"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"Writing myTuple.cpp\n","output_type":"stream"}],"id":"8dfa7a1c-28d8-4de1-ae19-bdb2a6d3e48e"},{"cell_type":"code","source":"!g++ -Wall -Wextra -c myTuple.cpp","metadata":{"trusted":true},"execution_count":4,"outputs":[{"name":"stdout","text":"myTuple.cpp: In function ‘std::ostream& operator<<(std::ostream&, const myTuple&)’:\nmyTuple.cpp:16:23: error: ‘int myTuple::fir’ is private within this context\n os << \"( \" << tup.fir << \" , \" << tup.sec << \" )\";\n ^~~\nmyTuple.cpp:6:7: note: declared private here\n int fir;\n ^~~\nmyTuple.cpp:16:43: error: ‘int myTuple::sec’ is private within this context\n os << \"( \" << tup.fir << \" , \" << tup.sec << \" )\";\n ^~~\nmyTuple.cpp:7:7: note: declared private here\n int sec;\n ^~~\n","output_type":"stream"}],"id":"25e56a5e-6c64-4d77-9a81-5d808f2b63b3"},{"cell_type":"markdown","source":"* That was to be expected. The attributes ```fir``` and ```sec``` of ```myTuple``` are private.\n* However, we do not want to make them accessible to everyone, just for the sake of one special function/operator.\n* But, we can do so **selectively**, with the friend statement.","metadata":{},"id":"092b284c-9b78-4ea9-9b9a-f43cc5f32612"},{"cell_type":"code","source":"%%file myTuple.cpp\n\n#include <iostream>\n\nclass myTuple {\n\n int fir;\n int sec;\n\n friend std::ostream& operator << ( std::ostream&, const myTuple& );\n\npublic:\n myTuple( int fir, int sec ) : fir(fir), sec(sec) {};\n\n};\n\nstd::ostream& operator << ( std::ostream &os, const myTuple& tup )\n{\n os << \"( \" << tup.fir << \" , \" << tup.sec << \" )\" << std::endl;\n \n // necessary for chaining:\n return os;\n}\n\nint main() {\n\n myTuple obj( 3, 5 );\n\n std::cout << \"Pair is: \" << obj << std::endl;\n}","metadata":{"trusted":true},"execution_count":5,"outputs":[{"name":"stdout","text":"Overwriting myTuple.cpp\n","output_type":"stream"}],"id":"ff341d41-7aa2-4f87-92f2-e189dd448d68"},{"cell_type":"code","source":"!g++ -Wall -Wextra myTuple.cpp","metadata":{"trusted":true},"execution_count":6,"outputs":[],"id":"c8560f81-10ef-4203-b3f3-8046255be25a"},{"cell_type":"code","source":"!./a.out","metadata":{"trusted":true},"execution_count":7,"outputs":[{"name":"stdout","text":"Pair is: ( 3 , 5 )\n\n","output_type":"stream"}],"id":"6a5f1cb3-7891-4cb8-b8ce-d3f6aa996ecc"},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[],"id":"94e6f340-7a06-4c59-8889-5088e41712f2"}]}
input_line_9:3:28: error: invalid operands to binary expression ('basic_ostream<char,std::char_traits<char> >' and '__cling_N52::myTuple')
input_line_9:3:28: error: invalid operands to binary expression ('basic_ostream<char,std::char_traits<char> >' and '__cling_N52::myTuple')
std::cout << "Pair is: " << obj << std::endl;
std::cout << "Pair is: " << obj << std::endl;
~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~
~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:245:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const void *' for 1st argument; take the address of the argument with &
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:245:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const void *' for 1st argument; take the address of the argument with &
operator<<(const void* __p)
operator<<(const void* __p)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/system_error:217:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const std::error_code' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/system_error:217:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const std::error_code' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:108:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ostream_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ostream_type &)' (aka 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &)') for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:108:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ostream_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ostream_type &)' (aka 'basic_ostream<char, std::char_traits<char> > &(*)(basic_ostream<char, std::char_traits<char> > &)') for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:117:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ios_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ios_type &)' (aka 'basic_ios<char, std::char_traits<char> > &(*)(basic_ios<char, std::char_traits<char> > &)') for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:117:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__ios_type &(*)(std::basic_ostream<char, std::char_traits<char> >::__ios_type &)' (aka 'basic_ios<char, std::char_traits<char> > &(*)(basic_ios<char, std::char_traits<char> > &)') for 1st argument
operator<<(__ios_type& (*__pf)(__ios_type&))
operator<<(__ios_type& (*__pf)(__ios_type&))
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:127:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:127:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument
operator<<(ios_base& (*__pf) (ios_base&))
operator<<(ios_base& (*__pf) (ios_base&))
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:166:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:166:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long' for 1st argument
operator<<(long __n)
operator<<(long __n)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:170:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:170:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long' for 1st argument
operator<<(unsigned long __n)
operator<<(unsigned long __n)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:174:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'bool' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:174:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'bool' for 1st argument
operator<<(bool __n)
operator<<(bool __n)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:178:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'short' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:178:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'short' for 1st argument
operator<<(short __n);
operator<<(short __n);
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:181:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned short' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:181:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned short' for 1st argument
operator<<(unsigned short __n)
operator<<(unsigned short __n)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:189:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'int' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:189:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'int' for 1st argument
operator<<(int __n);
operator<<(int __n);
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:192:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned int' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:192:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned int' for 1st argument
operator<<(unsigned int __n)
operator<<(unsigned int __n)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:201:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long long' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:201:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long long' for 1st argument
operator<<(long long __n)
operator<<(long long __n)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:205:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long long' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:205:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned long long' for 1st argument
operator<<(unsigned long long __n)
operator<<(unsigned long long __n)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:220:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'double' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:220:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'double' for 1st argument
operator<<(double __f)
operator<<(double __f)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:224:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'float' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:224:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'float' for 1st argument
operator<<(float __f)
operator<<(float __f)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:232:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long double' for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:232:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'long double' for 1st argument
operator<<(long double __f)
operator<<(long double __f)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:276:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__streambuf_type *' (aka 'basic_streambuf<char, std::char_traits<char> > *') for 1st argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:276:7: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'std::basic_ostream<char, std::char_traits<char> >::__streambuf_type *' (aka 'basic_streambuf<char, std::char_traits<char> > *') for 1st argument
operator<<(__streambuf_type* __sb);
operator<<(__streambuf_type* __sb);
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:511:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:511:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:517:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:517:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'char' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:523:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'signed char' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:523:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'signed char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:528:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned char' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:528:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'unsigned char' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:565:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:565:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:578:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const signed char *' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:578:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const signed char *' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:583:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const unsigned char *' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:583:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const unsigned char *' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/ostream.tcc:321:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/ostream.tcc:321:5: note: candidate function not viable: no known conversion from '__cling_N52::myTuple' to 'const char *' for 2nd argument
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/basic_string.h:6419:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/basic_string.h:6419:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against '__cling_N52::myTuple'
operator<<(basic_ostream<_CharT, _Traits>& __os,
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:548:5: note: candidate template ignored: could not match 'const _CharT *' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/ostream:548:5: note: candidate template ignored: could not match 'const _CharT *' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/shared_ptr.h:66:5: note: candidate template ignored: could not match '__shared_ptr<type-parameter-0-2, _Lp>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/shared_ptr.h:66:5: note: candidate template ignored: could not match '__shared_ptr<type-parameter-0-2, _Lp>' against '__cling_N52::myTuple'
operator<<(std::basic_ostream<_Ch, _Tr>& __os,
operator<<(std::basic_ostream<_Ch, _Tr>& __os,
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'
_DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)
_DEFINE_EXPR_BINARY_OPERATOR(<<, __shift_left)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr<type-parameter-0-0, typename type-parameter-0-0::value_type>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'
_DEFINE_BINARY_OPERATOR(<<, __shift_left)
_DEFINE_BINARY_OPERATOR(<<, __shift_left)
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'
operator _Op(const valarray<_Tp>& __v, \
operator _Op(const valarray<_Tp>& __v, \
^
^
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray<type-parameter-0-0>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray<type-parameter-0-0>' against '__cling_N52::myTuple'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'
/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/9.4.0/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'
Okay that obviously did not work. Problem is that ```<<``` does not know how to work with objects of type ```myTuple```.
Okay that obviously did not work. Problem is that ```<<``` does not know how to work with objects of type ```myTuple```.
* We can fix this by implementing a version of ```<<``` that understands it.
* We can fix this by implementing a version of ```<<``` that understands it.
* Different from our overloading of ```[ ]``` for our ```VectorClass```, we do not do this on the object. Instead we need to overload the free-function that is ```<<```.
* Different from our overloading of ```[ ]``` for our ```VectorClass```, we do not do this on the object. Instead we need to overload the free-function that is ```<<```.