Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/shuuji3/cpp-notebook.
Something went wrong. Try again.
cpp-notebook scratch.ipynb
3.8 kB 202 lines
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#include <iostream>\n", "#include <vector>" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(std::vector<int> &) { 1, 2, 3 }\n" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "std::vector<int> v{1,2,3};\n", "v" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "class Circle {\n", " private:\n", " double r;\n", " \n", " public:\n", " Circle(double r_) {\n", " r = r_;\n", " }\n", " double area() {\n", " return r * r;\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(Circle &) @0x10d6dd408\n" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "auto c1 = Circle(10);\n", "c1;" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(Circle &) @0x10d6dd538\n" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Circle c2{20};\n", "c2;" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(Circle &) @0x10d6dd668\n" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "auto c3 = Circle{30};\n", "c3;" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[1minput_line_15:2:7: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mdeclaration of variable 'Circle' with deduced type 'auto' requires an\n", " initializer\u001b[0m\n", " auto Circle c4{40};\n", "\u001b[0;1;32m ^\n", "\u001b[0m\u001b[1minput_line_15:2:13: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mexpected ';' at end of declaration\u001b[0m\n", " auto Circle c4{40};\n", "\u001b[0;1;32m ^\n", "\u001b[0m\u001b[0;32m ;\n", "\u001b[0m\u001b[1minput_line_15:3:1: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1muse of undeclared identifier 'c4'\u001b[0m\n", "c4;\n", "\u001b[0;1;32m^\n", "\u001b[0m" ] }, { "ename": "ename", "evalue": "evalue", "output_type": "error", "traceback": [] } ], "source": [ "auto Circle c4{40};\n", "c4;" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "c4.area();" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "C++14", "language": "", "name": "cling-cpp14" }, "language_info": { "codemirror_mode": "c++", "file_extension": ".c++", "mimetype": "text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 2}