diff --git a/notebooks/09_Inheritance.ipynb b/notebooks/09_Inheritance.ipynb index 43762fe92ea4e8d84b0e63da6b8f0f3aee8e25dc..5a5656ca7b50a3b368aa571a2559f57ac46f7e09 100644 --- a/notebooks/09_Inheritance.ipynb +++ b/notebooks/09_Inheritance.ipynb @@ -83,10 +83,214 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "id": "686fb768", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[1minput_line_11:5:49: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno viable overloaded '='\u001b[0m\n", + " void set_name( const std::string& n ) { name_ = n; }\n", + "\u001b[0;1;32m ~~~~~ ^ ~\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:688:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no known conversion from 'const std::string' (aka 'const basic_string<char>') to 'const char *' for 1st argument\u001b[0m\n", + " operator=(const _CharT* __s)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:699:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no known conversion from 'const std::string' (aka 'const basic_string<char>') to 'char' for 1st argument\u001b[0m\n", + " operator=(_CharT __c)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:716:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: 1st argument ('const std::string' (aka 'const basic_string<char>')) would lose const qualifier\u001b[0m\n", + " operator=(basic_string&& __str)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:779:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no known conversion from 'const std::string' (aka 'const basic_string<char>') to 'initializer_list<char>' for 1st argument\u001b[0m\n", + " operator=(initializer_list<_CharT> __l)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_11:8:55: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mreference to overloaded function could not be resolved; did you mean to call it?\u001b[0m\n", + " std::cout << \"[person] My name is \" << name_ << std::endl;\n", + "\u001b[0;1;32m ^~~~~~~~~\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:681:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mpossible target for call\u001b[0m\n", + " endl(basic_ostream<_CharT, _Traits>& __os)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:245:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'const void *' for 1st argument\u001b[0m\n", + " operator<<(const void* __p)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/system_error:262:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'const std::error_code' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:117:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching '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\u001b[0m\n", + " operator<<(__ios_type& (*__pf)(__ios_type&))\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:127:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'std::ios_base &(*)(std::ios_base &)' for 1st argument\u001b[0m\n", + " operator<<(ios_base& (*__pf) (ios_base&))\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:166:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'long' for 1st argument\u001b[0m\n", + " operator<<(long __n)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:170:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'unsigned long' for 1st argument\u001b[0m\n", + " operator<<(unsigned long __n)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:174:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'bool' for 1st argument\u001b[0m\n", + " operator<<(bool __n)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:178:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'short' for 1st argument\u001b[0m\n", + " operator<<(short __n);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:181:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'unsigned short' for 1st argument\u001b[0m\n", + " operator<<(unsigned short __n)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:189:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'int' for 1st argument\u001b[0m\n", + " operator<<(int __n);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:192:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'unsigned int' for 1st argument\u001b[0m\n", + " operator<<(unsigned int __n)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:201:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'long long' for 1st argument\u001b[0m\n", + " operator<<(long long __n)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:205:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'unsigned long long' for 1st argument\u001b[0m\n", + " operator<<(unsigned long long __n)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:220:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'double' for 1st argument\u001b[0m\n", + " operator<<(double __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:224:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'float' for 1st argument\u001b[0m\n", + " operator<<(float __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:232:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'long double' for 1st argument\u001b[0m\n", + " operator<<(long double __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:276:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function not viable: no overload of 'endl' matching 'std::basic_ostream<char, std::char_traits<char> >::__streambuf_type *' (aka 'basic_streambuf<char, std::char_traits<char> > *') for 1st argument\u001b[0m\n", + " operator<<(__streambuf_type* __sb);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:506:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function [with _CharT = char, _Traits = std::char_traits<char>] not viable: no overload of 'endl' matching 'char' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:511:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'char' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:517:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'char' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<char, _Traits>& __out, char __c)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:523:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'signed char' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<char, _Traits>& __out, signed char __c)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:528:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'unsigned char' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:589:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function [with _CharT = char, _Traits = std::char_traits<char>] not viable: no overload of 'endl' matching 'const char *' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:606:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'const char *' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<char, _Traits>& __out, const char* __s)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:619:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'const signed char *' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:624:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'const unsigned char *' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/ostream.tcc:321:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'const char *' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:79:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'std::_Resetiosflags' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Resetiosflags __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:109:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'std::_Setiosflags' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Setiosflags __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:143:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'std::_Setbase' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Setbase __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:178:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function [with _CharT = char, _Traits = std::char_traits<char>] not viable: no overload of 'endl' matching '_Setfill<char>' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Setfill<_CharT> __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:208:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'std::_Setprecision' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Setprecision __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:238:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function template not viable: no overload of 'endl' matching 'std::_Setw' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Setw __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:363:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate function [with _CharT = char, _Traits = std::char_traits<char>] not viable: no overload of 'endl' matching '_Put_time<char>' for 2nd argument\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_time<_CharT> __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:6480:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument '_Alloc'\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os,\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr.h:69:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument '_Tp'\u001b[0m\n", + " operator<<(std::basic_ostream<_Ch, _Tr>& __os,\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument '_Dom'\u001b[0m\n", + " _DEFINE_EXPR_BINARY_OPERATOR(<<, struct std::__shift_left)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:370:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const typename _Dom::value_type& __t, \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument '_Dom'\u001b[0m\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:396:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const valarray<typename _Dom::value_type>& __v, \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument '_Tp'\u001b[0m\n", + "_DEFINE_BINARY_OPERATOR(<<, __shift_left)\n", + "\u001b[0;1;32m^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1177:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const typename valarray<_Tp>::value_type& __t, \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:773:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument '_Tp'\u001b[0m\n", + " operator<<(_Ostream&& __os, const _Tp& __x)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/iomanip:311:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: couldn't infer template argument '_MoneyT'\u001b[0m\n", + " operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_money<_MoneyT> __f)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: could not match '_Expr' against 'basic_ostream'\u001b[0m\n", + " _DEFINE_EXPR_BINARY_OPERATOR(<<, struct std::__shift_left)\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:344:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: could not match '_Expr' against 'basic_ostream'\u001b[0m\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:357:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: could not match '_Expr' against 'basic_ostream'\u001b[0m\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:383:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: could not match 'valarray' against 'basic_ostream'\u001b[0m\n", + "_DEFINE_BINARY_OPERATOR(<<, __shift_left)\n", + "\u001b[0;1;32m^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1155:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate template ignored: could not match 'valarray' against 'basic_ostream'\u001b[0m\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1166:5: \u001b[0m\u001b[0;1;30mnote: \u001b[0mexpanded from macro '_DEFINE_BINARY_OPERATOR'\u001b[0m\n", + " operator _Op(const valarray<_Tp>& __v, \\\n", + "\u001b[0;1;32m ^\n", + "\u001b[0mIn file included from input_line_5:1:\n", + "In file included from /home/student/micromamba/envs/xeus/include/xeus/xinterpreter.hpp:17:\n", + "In file included from /home/student/micromamba/envs/xeus/include/xeus/xcomm.hpp:19:\n", + "In file included from /home/student/micromamba/envs/xeus/include/nlohmann/json.hpp:41:\n", + "In file included from /home/student/micromamba/envs/xeus/include/nlohmann/detail/input/binary_reader.hpp:25:\n", + "In file included from /home/student/micromamba/envs/xeus/include/nlohmann/detail/input/input_adapters.hpp:23:\n", + "In file included from /home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/istream:39:\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:609:8: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno member named 'setstate' in 'std::basic_ostream<char>'\u001b[0m\n", + " __out.setstate(ios_base::badbit);\n", + "\u001b[0;1;32m ~~~~~ ^\n", + "\u001b[0m\u001b[1minput_line_11:8:15: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of function template specialization 'std::operator<<<std::char_traits<char> >' requested here\u001b[0m\n", + " std::cout << \"[person] My name is \" << name_ << std::endl;\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "class person {\n", "\n", @@ -120,10 +324,48 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "id": "9c807fff", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[1minput_line_12:1:24: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mexpected class name\u001b[0m\n", + "class student : public person {\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_12:4:5: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mmember initializer 'person' does not name a non-static data member or base class\u001b[0m\n", + " person(name), program_(program) {}\n", + "\u001b[0;1;32m ^~~~~~~~~~~~\n", + "\u001b[0m\u001b[1minput_line_12:6:46: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1muse of undeclared identifier 'get_name'\u001b[0m\n", + " std::cout << \"[student] My name is \" << get_name()\n", + "\u001b[0;1;32m ^\n", + "\u001b[0mIn file included from input_line_5:1:\n", + "In file included from /home/student/micromamba/envs/xeus/include/xeus/xinterpreter.hpp:17:\n", + "In file included from /home/student/micromamba/envs/xeus/include/xeus/xcomm.hpp:19:\n", + "In file included from /home/student/micromamba/envs/xeus/include/nlohmann/json.hpp:41:\n", + "In file included from /home/student/micromamba/envs/xeus/include/nlohmann/detail/input/binary_reader.hpp:25:\n", + "In file included from /home/student/micromamba/envs/xeus/include/nlohmann/detail/input/input_adapters.hpp:23:\n", + "In file included from /home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/istream:39:\n", + "\u001b[1m/home/student/micromamba/envs/xeus/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:609:8: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno member named 'setstate' in 'std::basic_ostream<char>'\u001b[0m\n", + " __out.setstate(ios_base::badbit);\n", + "\u001b[0;1;32m ~~~~~ ^\n", + "\u001b[0m\u001b[1minput_line_12:6:15: \u001b[0m\u001b[0;1;30mnote: \u001b[0min instantiation of function template specialization 'std::operator<<<std::char_traits<char> >' requested here\u001b[0m\n", + " std::cout << \"[student] My name is \" << get_name()\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "class student : public person {\n", "\n", @@ -171,10 +413,55 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "id": "bd768c68", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[1minput_line_13:2:3: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1munknown type name 'person'\u001b[0m\n", + " person jane( \"Jane Doe\" );\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_13:4:3: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1munknown type name 'student'\u001b[0m\n", + " student joe( \"Joe Smith\", \"Geophysics\" );\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_13:6:3: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1munknown type name 'person'\u001b[0m\n", + " person pv(joe);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_13:7:3: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1muse of undeclared identifier 'person'; did you mean 'perror'?\u001b[0m\n", + " person& pr(joe); // or pr = joe\n", + "\u001b[0;1;32m ^~~~~~\n", + "\u001b[0m\u001b[0;32m perror\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/x86_64-conda-linux-gnu/sysroot/usr/include/stdio.h:841:13: \u001b[0m\u001b[0;1;30mnote: \u001b[0m'perror' declared here\u001b[0m\n", + "extern void perror (__const char *__s);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_13:8:3: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1muse of undeclared identifier 'person'; did you mean 'perror'?\u001b[0m\n", + " person* pp(&joe); // or pp = &joe\n", + "\u001b[0;1;32m ^~~~~~\n", + "\u001b[0m\u001b[0;32m perror\n", + "\u001b[0m\u001b[1m/home/student/micromamba/envs/xeus/x86_64-conda-linux-gnu/sysroot/usr/include/stdio.h:841:13: \u001b[0m\u001b[0;1;30mnote: \u001b[0m'perror' declared here\u001b[0m\n", + "extern void perror (__const char *__s);\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_13:10:3: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1muse of undeclared identifier 'pr'\u001b[0m\n", + " pr.all_info();\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m\u001b[1minput_line_13:11:3: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1muse of undeclared identifier 'pp'\u001b[0m\n", + " pp->all_info();\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " + ] + } + ], "source": [ "int main() {\n", "\n", @@ -198,20 +485,26 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "id": "780348e2", "metadata": {}, "outputs": [ { - "name": "stdout", + "name": "stderr", "output_type": "stream", "text": [ - "[person] My name is Jane Doe\n", - "[student] My name is Joe Smith, I study Geophysics\n", - "[person] My name is Joe Smith\n", - "[person] My name is Joe Smith\n", - "[person] My name is Joe Smith\n", - "Joe Smith" + "\u001b[1minput_line_14:2:2: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1muse of undeclared identifier 'main'\u001b[0m\n", + " main();\n", + "\u001b[0;1;32m ^\n", + "\u001b[0m" + ] + }, + { + "ename": "Interpreter Error", + "evalue": "", + "output_type": "error", + "traceback": [ + "Interpreter Error: " ] } ], @@ -253,7 +546,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "fd4597ea", "metadata": {}, "outputs": [], @@ -262,32 +555,32 @@ "\n", "public:\n", " person() = default;\n", - " person( const std::string& name ) : name(name) {};\n", + " person( const std::string& name ) : name_(name) {};\n", "\n", - " void set_name( const std::string& n ) { name = n; }\n", - " std::string get_name() const { return name; }\n", + " void set_name( const std::string& n ) { name_ = n; }\n", + " const std::string& get_name() const { return name_; }\n", "\n", " void all_info() const {\n", - " std::cout << \"[person] My name is \" << name << std::endl;\n", + " std::cout << \"[person] My name is \" << name_ << std::endl;\n", " }\n", "\n", "protected:\n", - " std::string name;\n", + " std::string name_;\n", "};\n", "\n", "class student : public person {\n", "\n", "public:\n", " student( const std::string& name, const std::string program ) :\n", - " person(name), program(program) {}\n", + " person(name), program_(program) {}\n", "\n", " void all_info() const {\n", - " std::cout << \"[student] My name is \" << name\n", - " << \", I study \" << program << std::endl;\n", + " std::cout << \"[student] My name is \" << name_\n", + " << \", I study \" << program_ << std::endl;\n", " }\n", "\n", "private:\n", - " std::string program;\n", + " std::string program_;\n", "};" ] }, @@ -296,7 +589,7 @@ "id": "459b408f", "metadata": {}, "source": [ - "Having changed `name` from `private` to `protected` in line 14, allows us to directly use it in line 25." + "Having changed `name_` from `private` to `protected` in line 14, allows us to directly use it in line 25." ] }, { @@ -329,17 +622,18 @@ "outputs": [], "source": [ "#include <iostream>\n", + "\n", "struct A {\n", - " A( int iVal ) : value(iVal) {};\n", - " int value;\n", + " A( int iVal ) : value_(iVal) {};\n", + " int value_;\n", "};\n", "\n", "struct B : public A {\n", - " B( int iVal, double dVal ) : A(iVal), value(dVal) {\n", - " std::cout << \"A::value = \" << A::value << \"\\n\"\n", - " << \"B::value = \" << value << std::endl;\n", + " B( int iVal, double dVal ) : A(iVal), value_(dVal) {\n", + " std::cout << \"A::value = \" << A::value_ << \"\\n\"\n", + " << \"B::value = \" << value_ << std::endl;\n", " };\n", - " double value;\n", + " double value_;\n", "};" ] }, @@ -421,7 +715,7 @@ "\n", "public:\n", " void func( int arg ) {\n", - " std::cout << \"Child::func() was called with argument '\"\n", + " std::cout << \"AnotherChild::func() was called with argument '\"\n", " << arg << \"'\" << std::endl;\n", " }\n", "\n", @@ -469,21 +763,30 @@ "id": "1fbaa676", "metadata": {}, "source": [ - "We can solve this be explicitely requesting inheritance of the constructor again with a `using` directive. Note that this will inherit all constructors, it cannot be done selectively." + "We can solve this by explicitely requesting inheritance of the constructor again with a `using` directive. Note that this will inherit all constructors, it cannot be done selectively." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "481fc3f5", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Smartie Clever\n" + ] + } + ], "source": [ "#include <iostream>\n", "class researcher : public person {\n", " using person::person;\n", "};\n", "researcher smart( \"Smartie Clever\" );\n", + "\n", "std::cout << smart.get_name() << std::endl;" ] }, @@ -497,19 +800,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "ed941226", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Smartie Clever\n" + ] + } + ], "source": [ "class researcher : public person {\n", + "\n", "public:\n", " using person::person; \n", " researcher( const std::string& n ) {\n", - " name = n;\n", - " std::cout << \"Hello \" << name << std::endl;\n", + " name_ = n;\n", + " std::cout << \"Hello \" << name_ << std::endl;\n", " }\n", "};\n", + "\n", "researcher smart( \"Smartie Clever\");" ] }, @@ -526,7 +839,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "1493af7c", "metadata": {}, "outputs": [], @@ -552,30 +865,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "7802babb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "GrandParent's c'tor invoked\n", + "Parent's c'tor invoked\n" + ] + } + ], "source": [ "Parent walton;" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "57215968", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "GrandParent's c'tor invoked\n", + "Parent's c'tor invoked\n", + "Child's c'tor invoked\n" + ] + } + ], "source": [ "auto jim_bob = new Child;" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "be7a63fe", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Child's d'tor invoked\n", + "Parent's d'tor invoked\n", + "GrandParent's d'tor invoked\n" + ] + } + ], "source": [ "delete jim_bob;" ] diff --git a/notebooks/10_Polymorphic_Classes.ipynb b/notebooks/10_Polymorphic_Classes.ipynb index 9b8d19be64c624c918d6800c6a6bafa41533444a..6d630264c31f2acfb8e78eea15f222263186c995 100644 --- a/notebooks/10_Polymorphic_Classes.ipynb +++ b/notebooks/10_Polymorphic_Classes.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 1, "id": "7942848b", "metadata": {}, "outputs": [], @@ -36,20 +36,20 @@ "class person {\n", "\n", "public:\n", - " person( const std::string& name ) : name(name) {};\n", + " person( const std::string& name ) : name_(name) {};\n", "\n", " void all_info() const {\n", - " std::cout << \"[person] My name is \" << name << std::endl;\n", + " std::cout << \"[person] My name is \" << name_ << std::endl;\n", " }\n", "\n", "protected:\n", - " std::string name;\n", + " std::string name_;\n", "};" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 2, "id": "f40024e2", "metadata": {}, "outputs": [], @@ -57,22 +57,22 @@ "class student : public person {\n", "\n", "public:\n", - " student( const std::string& name, const std::string program ) :\n", - " person(name), program(program) {}\n", + " student( const std::string& name, const std::string& program ) :\n", + " person(name), program_(program) {}\n", "\n", " void all_info() const {\n", - " std::cout << \"[student] My name is \" << name\n", - " << \", I study \" << program << std::endl;\n", + " std::cout << \"[student] My name is \" << name_\n", + " << \", I study \" << program_ << std::endl;\n", " }\n", "\n", "private:\n", - " std::string program;\n", + " std::string program_;\n", "};" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 3, "id": "459a1ce0", "metadata": {}, "outputs": [], @@ -81,15 +81,15 @@ "\n", "public:\n", " researcher( const std::string& name, const std::string& field ) :\n", - " person(name), field(field) {}\n", + " person(name), field_(field) {}\n", "\n", " void all_info() const {\n", - " std::cout << \"[researcher] My name is \" << name\n", - " << \", I work on problems in \" << field << std::endl;\n", + " std::cout << \"[researcher] My name is \" << name_\n", + " << \", I work on problems in \" << field_ << std::endl;\n", " }\n", "\n", "private:\n", - " std::string field;\n", + " std::string field_;\n", "};" ] }, @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 4, "id": "5ff4684f", "metadata": {}, "outputs": [], @@ -135,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 6, "id": "aebeaf35", "metadata": {}, "outputs": [ @@ -151,7 +151,7 @@ } ], "source": [ - "for( auto memb: uniMembers ) memb->all_info();" + "for( const auto memb: uniMembers ) memb->all_info();" ] }, { @@ -164,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 7, "id": "445c4d28", "metadata": {}, "outputs": [ @@ -206,7 +206,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 8, "id": "4b596bd2", "metadata": {}, "outputs": [], @@ -259,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 9, "id": "12bebbf9", "metadata": {}, "outputs": [ @@ -321,7 +321,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 10, "id": "f371e175-cbc1-45e4-b8bb-06b8ebc92ef1", "metadata": {}, "outputs": [ @@ -396,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 11, "id": "99352379", "metadata": {}, "outputs": [], @@ -408,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 12, "id": "454ccaaf", "metadata": {}, "outputs": [ @@ -435,7 +435,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 13, "id": "bd457522", "metadata": {}, "outputs": [], @@ -458,7 +458,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 14, "id": "4a0a85ba", "metadata": {}, "outputs": [ @@ -494,7 +494,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 16, "id": "3c824171", "metadata": {}, "outputs": [ @@ -527,7 +527,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 18, "id": "29c729c5", "metadata": {}, "outputs": [ @@ -544,7 +544,7 @@ "fail.cpp:14:10: warning: 'B::func3' hides overloaded virtual function [-Woverloaded-virtual]\n", " void func3() { std::cout << \"B::func3 is executing\" << std::endl; }; \n", " ^\n", - "fail.cpp:7:18: note: hidden overloaded virtual function 'A::func3' declared here: different qualifiers (const vs none)\n", + "fail.cpp:7:18: note: hidden overloaded virtual function 'A::func3' declared here: different qualifiers ('const' vs unqualified)\n", " virtual void func3() const { std::cout << \"A::func3 is executing\" << std::endl; }; \n", " ^\n", "2 warnings generated.\n" @@ -566,7 +566,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 1, "id": "8ab90c4e-a3a3-4d26-8be1-6783e75d8bdb", "metadata": {}, "outputs": [ @@ -599,7 +599,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 3, "id": "f4c9ca56-443e-477c-a1ee-869de3d44341", "metadata": {}, "outputs": [ @@ -607,20 +607,24 @@ "name": "stdout", "output_type": "stream", "text": [ - "fail.cpp:12:10: error: ‘void B::func1()’ marked ‘override’, but does not override\n", - " void func1() override { std::cout << \"B::func1 is executing\" << std::endl; };\n", - " ^~~~~\n", - "fail.cpp:13:18: error: ‘virtual void B::func2(int)’ marked ‘override’, but does not override\n", - " virtual void func2( int a ) override { std::cout << \"func2 from B: a = \" << a << std::endl; };\n", - " ^~~~~\n", - "fail.cpp:14:10: error: ‘void B::func3()’ marked ‘override’, but does not override\n", - " void func3() override { std::cout << \"B::func3 is executing\" << std::endl; };\n", - " ^~~~~\n" + "fail.cpp:12:18: error: only virtual member functions can be marked 'override'\n", + " void func1() override { std::cout << \"B::func1 is executing\" << std::endl; };\n", + " ^~~~~~~~~\n", + "fail.cpp:13:18: error: 'func2' marked 'override' but does not override any member functions\n", + " virtual void func2( int a ) override { std::cout << \"func2 from B: a = \" << a << std::endl; };\n", + " ^\n", + "fail.cpp:14:18: error: non-virtual member function marked 'override' hides virtual member function\n", + " void func3() override { std::cout << \"B::func3 is executing\" << std::endl; }; \n", + " ^\n", + "fail.cpp:7:18: note: hidden overloaded virtual function 'A::func3' declared here: different qualifiers ('const' vs unqualified)\n", + " virtual void func3() const { std::cout << \"A::func3 is executing\" << std::endl; }; \n", + " ^\n", + "3 errors generated.\n" ] } ], "source": [ - "!g++ fail.cpp" + "!clang++ fail.cpp" ] }, { @@ -629,12 +633,12 @@ "metadata": {}, "source": [ "#### Speficier: final\n", - "The `final` specifier allows is to express that this is the final implementation of a virtual method. Further child classes are then not allowed to override it anymore." + "The `final` specifier allows to express that this is the final implementation of a virtual method. Further child classes are then not allowed to override it anymore." ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 11, "id": "6c7d3d27-6622-497c-a621-ec8a207ae1ae", "metadata": {}, "outputs": [ @@ -653,17 +657,17 @@ "\n", "class GrandMother {\n", "public:\n", - " virtual void doIt( int a ) = 0;\n", + " virtual void doIt( int a ){};\n", " void func() {};\n", "};\n", "\n", "class Mother : public GrandMother {\n", "public:\n", - " void doIt( int a ) override // final // (1) creates an error in Daughter\n", + " void doIt( int a ) override // final (1) creates an error in Daughter\n", " {\n", " std::cout << a << \" + 3 = \" << a+3 << std::endl;\n", " }\n", - " // void func() final {}; // (2) will fail as GrandMother::func is not virtual\n", + " void func(); // final {}; // (2) will fail as GrandMother::func is not virtual\n", "};\n", "\n", "class Daughter : public Mother {\n", @@ -686,7 +690,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 12, "id": "55d0dcc1-2f25-4b27-812c-46b1009c6881", "metadata": {}, "outputs": [], @@ -696,7 +700,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 6, "id": "ae0745fb-02d6-4a15-b59d-08720bdcb1cc", "metadata": {}, "outputs": [ @@ -780,7 +784,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 20, "id": "24c9d364", "metadata": {}, "outputs": [ @@ -821,17 +825,35 @@ "\n", "int main( void ) {\n", " // Interface uninstantiable;\n", - " // VariantA obj1;\n", + " // Interface inter;\n", + " VariantA obj1;\n", " VariantB obj2;\n", "}" ] }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 21, "id": "a6159a96-102e-478f-8e06-68e51e77e1d0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pure.cpp: In function ‘int main()’:\n", + "pure.cpp:29:12: error: cannot declare variable ‘obj1’ to be of abstract type ‘VariantA’\n", + " 29 | VariantA obj1;\n", + " | ^~~~\n", + "pure.cpp:11:7: note: because the following virtual functions are pure within ‘VariantA’:\n", + " 11 | class VariantA : public Interface {\n", + " | ^~~~~~~~\n", + "pure.cpp:7:18: note: ‘virtual double Interface::getValue()’\n", + " 7 | virtual double getValue() = 0;\n", + " | ^~~~~~~~\n" + ] + } + ], "source": [ "!g++ pure.cpp" ] @@ -839,7 +861,7 @@ { "cell_type": "code", "execution_count": null, - "id": "400a8a90-8f2a-468c-a9ba-4f124029858e", + "id": "b087868b-69cb-4dd2-b266-f68271eea1fe", "metadata": {}, "outputs": [], "source": [] @@ -847,16 +869,16 @@ ], "metadata": { "kernelspec": { - "display_name": "C++14", - "language": "C++14", - "name": "xcpp14" + "display_name": "C++17", + "language": "C++17", + "name": "xcpp17" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", - "version": "14" + "version": "17" } }, "nbformat": 4,