Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit 8faf9764 authored by ROUVREAU Vincent's avatar ROUVREAU Vincent Committed by GILLES Sebastien
Browse files

Some typo, add coliru link, rephrasing and move code in code cells

parent 9221c943
......@@ -138,7 +138,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"C++ provides the way to mimic this behaviour with **operator overloading**. This is a very powerful conceit, but also one that should be approached with some care...\n",
"C++ provides the way to mimic this behaviour with **operator overloading**. This is a very powerful concept, but also one that should be approached with some care...\n",
"\n",
"We will see the general way to define such an operator in this notebook and see in dedicated notebooks which are the ones specifically useful.\n",
"\n",
......@@ -248,7 +248,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We see in the definition of the operator+ that both `Vector2` added aren't symmetric: one is the data attribute while the other is the data attribute of an object given as an argument.\n",
"We see in the definition of the `operator+` that both `Vector2` added aren't symmetric: one is the data attribute while the other is the data attribute of an object given as an argument.\n",
"\n",
"As a side note, please remark the `operator+` implementation is able to reach the private data attributes of the argument `v`; this means the private status is set **at class level** and not at object level.\n",
"\n",
......@@ -413,18 +413,25 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"However, pay attention to the fact this operator is not commutative: when you call \n",
"\n",
"````\n",
"Vector4 vector_plus_5 = vector + 5.;\n",
"````\n",
"\n",
"it is indeed a shortcut to\n",
"\n",
"````\n",
"Vector4 vector_plus_5 = vector.operator+(5.);\n",
"````\n",
"\n",
"However, pay attention to the fact this operator is not commutative. It is indeed a shortcut to"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"{\n",
" Vector4 vector(5., 3.2, -1.);\n",
" Vector4 vector_plus_5 = vector.operator+(5.);\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and the following won't compile:"
]
},
......@@ -444,10 +451,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want it to be possible, you have to define the operator with arguments in both orders; you therefore need to use out-of-class prototype of the function (can't show it currently due to Xeus-cling limitation).\n",
"If you want it to be possible, you have to define the operator with arguments in both orders; you therefore need to use out-of-class prototype of the function (can't show it currently due to Xeus-cling limitation, available [@Coliru](https://coliru.stacked-crooked.com/a/bb8130aec13bdf26)).\n",
"\n",
"Of course, if you do so you should define one in way of the other:\n",
"\n"
"Of course, it is a **good practice** to define one in way of the other:"
]
},
{
......@@ -658,12 +664,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As for constructors, you might add the keyword `explicit` in the class declaration to ensure no implicit conversion occurs:\n",
"\n",
"````\n",
"As for constructors, you might add the keyword `explicit` in the class declaration to ensure no implicit conversion occurs:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"explicit operator int() const;\n",
"explicit operator double() const;\n",
"````"
"explicit operator double() const;"
]
},
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment