From 0e649936bd35b4be9c9577f4c7e16c4ded162a5c Mon Sep 17 00:00:00 2001 From: Marcus Mohr <marcus.mohr@lmu.de> Date: Tue, 18 Jan 2022 16:36:37 +0100 Subject: [PATCH] Small correction --- notebooks/11_Template_Basics.ipynb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/notebooks/11_Template_Basics.ipynb b/notebooks/11_Template_Basics.ipynb index 95d53c8..4adfc3c 100644 --- a/notebooks/11_Template_Basics.ipynb +++ b/notebooks/11_Template_Basics.ipynb @@ -1072,7 +1072,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "4fd246ab", + "id": "05d338d8", "metadata": {}, "outputs": [], "source": [ @@ -1080,17 +1080,16 @@ "\n", "template< typename T, int N >\n", "struct StaticArray {\n", - " int getSize() { return N; };\n", - " T data[N];\n", + " int getSize() { return N; };\n", + " T data[N];\n", "};\n", "\n", "int main() {\n", "\n", - " StaticArray< float, 5 > shortVec;\n", - " StaticArray< short, 100 > longVec;\n", - " StaticArray< float, 5 > shortVec2;\n", - " std::cout << longVec.getSize();\n", - " \n", + " StaticArray< float, 5 > shortVec;\n", + " StaticArray< short, 100 > longVec;\n", + " StaticArray< float, 5 > shortVec2;\n", + " std::cout << longVec.getSize();\n", "}" ] }, @@ -1122,7 +1121,7 @@ "Answers:\n", "- The instantiation of `StaticArray< float, 5 >` is implicit. Thus, it is lazy. The compiler knows that the member function `getSize()` exists and what its prototype is, but it will not generate machine code for it, as it is never called.\n", "- The class `StaticArray< float, 5 >` itself represents a datatype. While we can have multiple objects of this type, the template will only be instantiated once, for the same arguments.</br>\n", - "(Note: That's not necessarily true for multiple compilation units! If multiple instances get generated the linker takes care of uniqueness.)*" + " *(Note: That's not necessarily true for multiple compilation units! If multiple instances get generated the linker takes care of uniqueness.)*" ] }, { -- GitLab