{"id":6866,"date":"2024-02-07T11:18:02","date_gmt":"2024-02-07T17:18:02","guid":{"rendered":"https:\/\/www.logikalsolutions.com\/wordpress\/?p=6866"},"modified":"2024-02-08T16:42:41","modified_gmt":"2024-02-08T22:42:41","slug":"delete","status":"publish","type":"post","link":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/","title":{"rendered":"C++ \u2013 Defaults and Deletes \u2013 Pt. 3"},"content":{"rendered":"\n<p>In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is that the default deconstructor does basically nothing. Near Heap allocations are reclaimed automatically when you return from a method\/function. For Far Heap objects all it does is free the allocation. It will not free any sub allocations. You have already been shown the code for the ImplicitClass so we will not discuss it again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">NoFarHeap.h<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/*\n * nearheapclass.h\n *\n *  Created on: Feb 1, 2024\n *      Author: roland\n *\/\n\n#ifndef NOFARHEAP_H_\n#define NOFARHEAP_H_\n\n#include &lt;optional&gt;\n\nclass NoFarHeap\n{\npublic:\n\tNoFarHeap() = default;\n\texplicit NoFarHeap( int i,\n\t\t\t\t\t\t\tstd::optional&lt;double&gt; dbl = std::nullopt,\n\t\t\t\t\t\t\tstd::optional&lt;const char *&gt; txt = std::nullopt);\n\n\tNoFarHeap( const NoFarHeap &amp;other) = default;\n\n\tvirtual ~NoFarHeap() = default;\n\n\tint get_int();\n\tdouble get_dbl();\n\tchar *get_buffer();\n\n\tvoid set_int( int i);\n\tvoid set_dbl( double d);\n\tvoid set_buffer_content( char *txt);\n\nprivate:\n\tint\t\tm_int {25};\n\tdouble\tm_dbl {3.14159};\t\/\/ yes, I used PI\n\tchar\tm_buffer[2048] {'\\0'};\n};\n\n#endif \/* NOFARHEAP_H_ *\/\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6B737C\">\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> * nearheapclass.h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *  Created on: Feb 1, 2024<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *      Author: roland<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#ifndef<\/span><span style=\"color: #B392F0\"> NOFARHEAP_H_<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#define<\/span><span style=\"color: #B392F0\"> NOFARHEAP_H_<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;optional&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">class<\/span><span style=\"color: #B392F0\"> NoFarHeap<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">public<\/span><span style=\"color: #BBBBBB\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tNoFarHeap() <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">default<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">explicit<\/span><span style=\"color: #B392F0\"> NoFarHeap( <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> i<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">optional&lt;<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">&gt; dbl <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">optional&lt;<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">&gt; txt <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tNoFarHeap( <\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> NoFarHeap <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">other) <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">default<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">virtual<\/span><span style=\"color: #B392F0\"> ~NoFarHeap() <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">default<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> get_int();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> get_dbl();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">get_buffer();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> set_int( <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> i);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> set_dbl( <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> d);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> set_buffer_content( <\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">txt);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">private<\/span><span style=\"color: #BBBBBB\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\">\t\tm_int {<\/span><span style=\"color: #F8F8F8\">25<\/span><span style=\"color: #B392F0\">};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">\tm_dbl {<\/span><span style=\"color: #F8F8F8\">3.14159<\/span><span style=\"color: #B392F0\">};<\/span><span style=\"color: #6B737C\">\t\/\/ yes, I used PI<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #79B8FF\">m_buffer<\/span><span style=\"color: #B392F0\">[<\/span><span style=\"color: #F8F8F8\">2048<\/span><span style=\"color: #B392F0\">] {<\/span><span style=\"color: #FFAB70\">&#39;\\0&#39;<\/span><span style=\"color: #B392F0\">};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#endif<\/span><span style=\"color: #6B737C\"> \/* NOFARHEAP_H_ *\/<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>I called this class NoFarHeap because it has no dynamic memory allocations. We took the compiler defaults for the default and copy constructor. If you read <a href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/\">this post on std::optional<\/a> then you recognize the only constructor I coded. The benefit of std::optional is it allows you to skip over parameters without knowing their default values and without having to have the coded in many places. It has drawbacks though.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"NoFarHeap abc( 32, std::nullopt, &quot;I want this text first&quot;);\n\nNoFarHeap def( 27);\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">NoFarHeap abc( <\/span><span style=\"color: #F8F8F8\">32<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;I want this text first&quot;<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">NoFarHeap def( <\/span><span style=\"color: #F8F8F8\">27<\/span><span style=\"color: #B392F0\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>When the most frequent use case is just changing the first parameter of the class constructor, std::nullopt works great for the rest. As you can see, it is just cumbersome when you want to change first and last.<\/p>\n\n\n\n<p>In case you do not know, at line 36, we declare m_buffer and initialize the entire thing to nulls. For this class I also allow the unsafe practice of returning the actual m_buffer pointer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">NearHeapClass.cpp<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/*\n * nearheapclass.cpp\n *\n *  Created on: Feb 1, 2024\n *      Author: roland\n *\/\n\n#include &quot;nofarheap.h&quot;\n\n#include &lt;cstring&gt;\n\n\nNoFarHeap::NoFarHeap(int i, std::optional&lt;double&gt; dbl, std::optional&lt;const char *&gt; txt) :\n\t\tm_int(i)\n{\n\tif (dbl.has_value())\n\t{\n\t\tm_dbl = dbl.value();\n\t}\n\n\tif (txt.has_value())\n\t{\n\t\tstrncpy( m_buffer, txt.value(), sizeof(m_buffer)-1);\n\t}\n}\n\nint NoFarHeap::get_int()\n{\n\treturn (m_int);\n}\n\ndouble NoFarHeap::get_dbl()\n{\n\treturn (m_dbl);\n}\n\nchar *NoFarHeap::get_buffer()\n{\n\treturn (m_buffer);\n}\n\nvoid NoFarHeap::set_int(int i)\n{\n\tm_int = i;\n}\n\nvoid NoFarHeap::set_dbl(double d)\n{\n\tm_dbl = d;\n}\n\nvoid NoFarHeap::set_buffer_content(char *txt)\n{\n\tstrncpy( m_buffer, txt, sizeof(m_buffer)-1);\n}\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6B737C\">\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> * nearheapclass.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *  Created on: Feb 1, 2024<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *      Author: roland<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;nofarheap.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;cstring&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">NoFarHeap<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">NoFarHeap(<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> i<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">optional<\/span><span style=\"color: #F97583\">&lt;double&gt;<\/span><span style=\"color: #B392F0\"> dbl<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">optional<\/span><span style=\"color: #F97583\">&lt;const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*&gt;<\/span><span style=\"color: #B392F0\"> txt) :<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tm_int(i)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">dbl<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tm_dbl <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">dbl<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">value();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">txt<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstrncpy( m_buffer<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">txt<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">value()<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">sizeof<\/span><span style=\"color: #B392F0\">(m_buffer)<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #F8F8F8\">1<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> NoFarHeap<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">get_int()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (m_int);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> NoFarHeap<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">get_dbl()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (m_dbl);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">NoFarHeap<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">get_buffer()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (m_buffer);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> NoFarHeap<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">set_int(<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> i)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tm_int <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> i;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> NoFarHeap<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">set_dbl(<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> d)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tm_dbl <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> d;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> NoFarHeap<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">set_buffer_content(<\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">txt)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstrncpy( m_buffer<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> txt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">sizeof<\/span><span style=\"color: #B392F0\">(m_buffer)<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #F8F8F8\">1<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Only thing worthy of note here is line 23 where we <em>copy<\/em> the text into buffer instead of changing the pointer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FarHeapClass.h<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/*\n * dynamicclass.h\n *\n *  Created on: Feb 1, 2024\n *      Author: roland\n *\/\n\n#ifndef FARHEAPCLASS_H_\n#define FARHEAPCLASS_H_\n\n#include &lt;string&gt;\n\nclass FarHeapClass\n{\npublic:\n\texplicit FarHeapClass(int portNumber = 1, int bufferSize = 2048);\n\tFarHeapClass(const FarHeapClass &amp;other) = delete;\n\tvirtual ~FarHeapClass();\n\n\tint buffer_size();\n\tint port_number();\n\n\tvoid fake_read_from_port();\n\n\tstd::string buffer_content();\n\n\tFarHeapClass&amp; operator=(const FarHeapClass&amp;) = delete;\n\nprivate:\n\tint m_buffer_size;\n\tint m_port_number;\n\tchar *m_buffer {};\n\n};\n\n#endif \/* FARHEAPCLASS_H_ *\/\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6B737C\">\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> * dynamicclass.h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *  Created on: Feb 1, 2024<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *      Author: roland<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#ifndef<\/span><span style=\"color: #B392F0\"> FARHEAPCLASS_H_<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#define<\/span><span style=\"color: #B392F0\"> FARHEAPCLASS_H_<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;string&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">class<\/span><span style=\"color: #B392F0\"> FarHeapClass<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">public<\/span><span style=\"color: #BBBBBB\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">explicit<\/span><span style=\"color: #B392F0\"> FarHeapClass(<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> portNumber <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">1<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> bufferSize <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">2048<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tFarHeapClass(<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> FarHeapClass <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">other) <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">delete<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">virtual<\/span><span style=\"color: #B392F0\"> ~FarHeapClass();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> buffer_size();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> port_number();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> fake_read_from_port();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string buffer_content();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tFarHeapClass<\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">operator<\/span><span style=\"color: #B392F0\">=(<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> FarHeapClass<\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">) <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">delete<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">private<\/span><span style=\"color: #BBBBBB\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> m_buffer_size;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> m_port_number;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">m_buffer {};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#endif<\/span><span style=\"color: #6B737C\"> \/* FARHEAPCLASS_H_ *\/<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Pay close attention to line 17. I delete the copy constructor. Why did I do that? Line 32. This class dynamically allocates its buffer. It is also why line 27 deletes the assignment operator. <\/p>\n\n\n\n<p>You should also pay attention to line 18. There is a growing academic trend of wanting all destructors to be declared virtual. <em>I&#8217;m not on board with it<\/em>, but it is a growing trend. The &#8220;philosophy&#8221; is that if someone derives a class from yours and is passing things around via a base class pointer then does a <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"delete ptr;\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">delete<\/span><span style=\"color: #B392F0\"> ptr;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Only the base class destructor will be called\/used. Putting virtual on the destructor forces the compiler to look up the actual class type and call the correct destructor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FarHeapClass.cpp<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/*\n * dynamicclass.cpp\n *\n *  Created on: Feb 1, 2024\n *      Author: roland\n *\/\n#include &lt;cstring&gt;\n#include &lt;iostream&gt;\n\n#include &quot;farheapclass.h&quot;\n\nFarHeapClass::FarHeapClass(int portNumber, int bufferSize) :\n  m_port_number(portNumber),\n  m_buffer_size(bufferSize)\n{\n\tm_buffer = new char [ m_buffer_size];\n\tmemset( m_buffer, '\\0', m_buffer_size);\n}\n\nFarHeapClass::~FarHeapClass()\n{\n\tif (m_buffer != nullptr)\n\t{\n\t\tdelete m_buffer;\n\t\tm_buffer = nullptr;  \/\/ I like to do this just in case though it shouldn't matter\n\t}\n}\n\nint FarHeapClass::buffer_size()\n{\n\treturn (m_buffer_size);\n}\n\nint FarHeapClass::port_number()\n{\n\treturn (m_port_number);\n}\n\nstd::string FarHeapClass::buffer_content()\n{\n\tstd::string str(m_buffer);\n\treturn (str);  \/\/ returned by value\n}\n\nvoid FarHeapClass::fake_read_from_port()\n{\n\tif (m_buffer != nullptr)\n\t{\n\t\tstd::string some_text;\n\t\tstd::cout &lt;&lt; &quot;=========== Please enter some text: &quot;;\n\t\tstd::getline( std::cin, some_text);\n\n\t\tstrncpy(m_buffer, some_text.c_str(), m_buffer_size-1);\n\t}\n}\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6B737C\">\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> * dynamicclass.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *  Created on: Feb 1, 2024<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *      Author: roland<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;cstring&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;farheapclass.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">FarHeapClass<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">FarHeapClass(<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> portNumber<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> bufferSize) :<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">  m_port_number(portNumber)<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">  m_buffer_size(bufferSize)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tm_buffer <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> [ m_buffer_size];<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tmemset( m_buffer<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;\\0&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> m_buffer_size);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">FarHeapClass<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #F97583\">~<\/span><span style=\"color: #B392F0\">FarHeapClass()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (m_buffer <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">nullptr<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t<\/span><span style=\"color: #F97583\">delete<\/span><span style=\"color: #B392F0\"> m_buffer;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tm_buffer <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">nullptr<\/span><span style=\"color: #B392F0\">;<\/span><span style=\"color: #6B737C\">  \/\/ I like to do this just in case though it shouldn&#39;t matter<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> FarHeapClass<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">buffer_size()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (m_buffer_size);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> FarHeapClass<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">port_number()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (m_port_number);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string FarHeapClass<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">buffer_content()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string str(m_buffer);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (str);<\/span><span style=\"color: #6B737C\">  \/\/ returned by value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> FarHeapClass<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">fake_read_from_port()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (m_buffer <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">nullptr<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string some_text;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;=========== Please enter some text: &quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">getline( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cin<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> some_text);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstrncpy(m_buffer<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">some_text<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">c_str()<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> m_buffer_size<\/span><span style=\"color: #F97583\">-<\/span><span style=\"color: #F8F8F8\">1<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Lines 16 and 17 are where we allocate our buffer and null it out. You will note that I do not let users get direct access to the buffer. Here we return a string.<\/p>\n\n\n\n<p>While this class may seem hokey, I modeled it after many I&#8217;ve had to do in the embedded systems world. Usually for serial, but any other kind of port I\/O. I just didn&#8217;t muddy the class up with platform specific port I\/O code. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">DefaultsAndDeletes.cpp<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(3 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#include &lt;iostream&gt;\n#include &quot;config.h&quot;\n\n#include &quot;implicitclass.h&quot;\n#include &quot;nofarheap.h&quot;\n#include &quot;farheapclass.h&quot;\n\nvoid dump_implicit( std::string label, ImplicitClass &amp;ic)\n{\n\tstd::cout &lt;&lt; label &lt;&lt; &quot;   fred: &quot; &lt;&lt; ic.fred &lt;&lt; &quot;  ethyl: &quot; &lt;&lt; ic.ethyl\n\t\t\t  &lt;&lt; &quot;  status: &quot; &lt;&lt; ic.statusStr &lt;&lt; std::endl;\n\n}\n\nvoid dump_noFarHeapClass( std::string label, NoFarHeap *ptr)\n{\n\tif (ptr != nullptr)\n\t{\n\tstd::cout &lt;&lt; &quot;** &quot; &lt;&lt; label &lt;&lt; &quot;  int: &quot; &lt;&lt; ptr-&gt;get_int()\n\t\t\t  &lt;&lt; &quot;  dbl: &quot; &lt;&lt; ptr-&gt;get_dbl()\n\t\t\t  &lt;&lt; &quot;  buffer: &quot; &lt;&lt; ptr-&gt;get_buffer() &lt;&lt; std::endl;\n\t}\n}\n\nvoid dump_farHeapClass( std::string label, FarHeapClass *ptr)\n{\n\tif (ptr != nullptr)\n\t{\n\t\tstd::cout &lt;&lt; &quot;-- &quot; &lt;&lt; label &lt;&lt; &quot;  buffer_size: &quot; &lt;&lt;\n\t\t\t\tptr-&gt;buffer_size() &lt;&lt; &quot;  port_number: &quot; &lt;&lt;\n\t\t\t\tptr-&gt;port_number() &lt;&lt; &quot;  content: &quot; &lt;&lt;\n\t\t\t\tptr-&gt;buffer_content() &lt;&lt; std::endl;\n\t}\n}\n\nint main(int argc, char **argv) {\n\tstd::cout &lt;&lt; &quot;DefaultsAndDeletes&quot; &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;Version &quot; &lt;&lt; DefaultsAndDeletes_VERSION_MAJOR &lt;&lt; &quot;.&quot; &lt;&lt; DefaultsAndDeletes_VERSION_MINOR &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;;;;;;;;;;;;;;;;;;;;&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;            Implicit Class Examples&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;;;;;;;;;;;;;;;;;;;;&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\n\tImplicitClass lucy;\n\tdump_implicit( &quot;lucy&quot;, lucy);\n\n\tImplicitClass young {8, 9.6, &quot;kids next door&quot;};\n\tdump_implicit( &quot;young&quot;, young);\n\n\tImplicitClass ricki {lucy};\n\tlucy = young;\t\/\/ be young again\n\n\tdump_implicit( &quot;second lucy&quot;, lucy);\n\tdump_implicit( &quot;ricky&quot;, ricki);\n\n\tstd::cout &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;;;;;;;;;;;;;;;;;;;;&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;            NoFarHeap Class Examples&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;;;;;;;;;;;;;;;;;;;;&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\n\t\/\/ this class doesn't dynamically allocate anything\n\t\/\/\n\tNoFarHeap firstVar;\n\tdump_noFarHeapClass( &quot;firstVar: &quot;, &amp;firstVar);\n\n\tNoFarHeap secondVar(32767, 98.5);\n\tdump_noFarHeapClass( &quot;secondVar: &quot;, &amp;secondVar);\n\n\t\/\/ just because it doesn't use the heap doesn't mean it cannot be on\n\t\/\/ the heap\n\t\/\/\n\tNoFarHeap *thirdVar = new NoFarHeap(747, 3.33333, &quot;Don't fly MAX&quot;);\n\tdump_noFarHeapClass( &quot;thirdVar: &quot;, thirdVar);\n\n\t*thirdVar = secondVar;\n\tdump_noFarHeapClass( &quot;thirdVar after assignment: &quot;, thirdVar);\n\n\tNoFarHeap fourthVar( *thirdVar);\n\tdump_noFarHeapClass( &quot;fourthVar: &quot;, &amp;fourthVar);\n\n\tdelete thirdVar;\n\n\tstd::cout &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;;;;;;;;;;;;;;;;;;;;&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;            FarHeapClass Examples&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;;;;;;;;;;;;;;;;;;;;&quot; &lt;&lt; std::endl &lt;&lt; std::endl;\n\n\tFarHeapClass h1;\n\tdump_farHeapClass( &quot;Default constructor: &quot;, &amp;h1);\n\n\tFarHeapClass *hp1 = new FarHeapClass( 2, 36000);\n\thp1-&gt;fake_read_from_port();\n\tdump_farHeapClass( &quot;After faking read: &quot;, hp1);\n\n\tdelete hp1;\n\n\tstd::cout &lt;&lt; std::endl &lt;&lt; std::endl &lt;&lt; &quot;finished&quot; &lt;&lt; std::endl;\n\n\treturn (0);\n}\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;config.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;implicitclass.h&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;nofarheap.h&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;farheapclass.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> dump_implicit( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string label<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> ImplicitClass <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">ic)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> label <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;   fred: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">ic<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">fred <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  ethyl: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">ic<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">ethyl<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t  <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  status: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">ic<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">statusStr <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> dump_noFarHeapClass( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string label<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> NoFarHeap <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">ptr)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (ptr <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">nullptr<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;** &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> label <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  int: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">get_int()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t  <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  dbl: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">get_dbl()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t  <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  buffer: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">get_buffer() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> dump_farHeapClass( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string label<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> FarHeapClass <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">ptr)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (ptr <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">nullptr<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;-- &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> label <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  buffer_size: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t<\/span><span style=\"color: #79B8FF\">ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">buffer_size() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  port_number: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t<\/span><span style=\"color: #79B8FF\">ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">port_number() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  content: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t<\/span><span style=\"color: #79B8FF\">ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">buffer_content() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> main(<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> argc<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">**<\/span><span style=\"color: #B392F0\">argv) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;DefaultsAndDeletes&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;Version &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> DefaultsAndDeletes_VERSION_MAJOR <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;.&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> DefaultsAndDeletes_VERSION_MINOR <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;;;;;;;;;;;;;;;;;;;;&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;            Implicit Class Examples&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;;;;;;;;;;;;;;;;;;;;&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tImplicitClass lucy;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_implicit( <\/span><span style=\"color: #FFAB70\">&quot;lucy&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> lucy);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tImplicitClass young {<\/span><span style=\"color: #F8F8F8\">8<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">9.6<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;kids next door&quot;<\/span><span style=\"color: #B392F0\">};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_implicit( <\/span><span style=\"color: #FFAB70\">&quot;young&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> young);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tImplicitClass ricki {lucy};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tlucy <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> young;<\/span><span style=\"color: #6B737C\">\t\/\/ be young again<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_implicit( <\/span><span style=\"color: #FFAB70\">&quot;second lucy&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> lucy);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_implicit( <\/span><span style=\"color: #FFAB70\">&quot;ricky&quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> ricki);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;;;;;;;;;;;;;;;;;;;;&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;            NoFarHeap Class Examples&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;;;;;;;;;;;;;;;;;;;;&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/\/ this class doesn&#39;t dynamically allocate anything<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tNoFarHeap firstVar;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_noFarHeapClass( <\/span><span style=\"color: #FFAB70\">&quot;firstVar: &quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">firstVar);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tNoFarHeap secondVar(<\/span><span style=\"color: #F8F8F8\">32767<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">98.5<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_noFarHeapClass( <\/span><span style=\"color: #FFAB70\">&quot;secondVar: &quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">secondVar);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/\/ just because it doesn&#39;t use the heap doesn&#39;t mean it cannot be on<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/\/ the heap<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tNoFarHeap <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">thirdVar <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #B392F0\"> NoFarHeap(<\/span><span style=\"color: #F8F8F8\">747<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">3.33333<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;Don&#39;t fly MAX&quot;<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_noFarHeapClass( <\/span><span style=\"color: #FFAB70\">&quot;thirdVar: &quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> thirdVar);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">thirdVar <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> secondVar;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_noFarHeapClass( <\/span><span style=\"color: #FFAB70\">&quot;thirdVar after assignment: &quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> thirdVar);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tNoFarHeap fourthVar( <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">thirdVar);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_noFarHeapClass( <\/span><span style=\"color: #FFAB70\">&quot;fourthVar: &quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">fourthVar);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">delete<\/span><span style=\"color: #B392F0\"> thirdVar;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;;;;;;;;;;;;;;;;;;;;&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;            FarHeapClass Examples&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;;;;;;;;;;;;;;;;;;;;&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tFarHeapClass h1;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_farHeapClass( <\/span><span style=\"color: #FFAB70\">&quot;Default constructor: &quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">h1);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tFarHeapClass <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">hp1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #B392F0\"> FarHeapClass( <\/span><span style=\"color: #F8F8F8\">2<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">36000<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #79B8FF\">hp1<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">fake_read_from_port();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tdump_farHeapClass( <\/span><span style=\"color: #FFAB70\">&quot;After faking read: &quot;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> hp1);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">delete<\/span><span style=\"color: #B392F0\"> hp1;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;finished&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #F8F8F8\">0<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Discussion<\/h2>\n\n\n\n<p>We will start our discussion at line 72 of the main module. Just because I called the class NoFarHeap doesn&#8217;t mean I can&#8217;t create one on the far heap via new.<\/p>\n\n\n\n<p>Lines 81 and 95 where I delete the things I create need to be discussed. In fact, I&#8217;m going to re-use an image.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"807\" height=\"274\" src=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/destructor-101.png\" alt=\"\" class=\"wp-image-6863\" srcset=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/destructor-101.png 807w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/destructor-101-300x102.png 300w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/destructor-101-768x261.png 768w\" sizes=\"(max-width: 807px) 100vw, 807px\" \/><\/figure>\n<\/div>\n\n\n<p>You are responsible for deleting everything you create. I work in the embedded systems world where we can&#8217;t let things consume memory because our stuff runs for weeks on end. I can also tell you that first bullet point is basically bullshit. If you are on OpenVMS or a mainframe it is true of every program no matter the language. Those platforms originated for time sharing and their accounting systems keeps track of every byte of RAM.<\/p>\n\n\n\n<p>On the weaker feebler x86, Arm, etc. platforms, the operating systems are not robust. What they define as a process is too light to even be a thread on a real platform. When you allocate stuff inside threads or lambdas don&#8217;t expect it to go away when you exit. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Application Frameworks<\/h3>\n\n\n\n<p>I&#8217;ve <a href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/medical-device-companies-using-qt\/\">written about Qt<\/a> many times on here. I&#8217;ve pointed you to <a href=\"https:\/\/www.copperspice.com\/\">CopperSpice<\/a> and <a href=\"https:\/\/www.wxwidgets.org\/\">wxWidgets<\/a> as well. One of the big draws to these frameworks was garbage collection. Told you that <a href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/application-frameworks\/\">in this post<\/a>. Too many programmers were too lazy (or unskilled) when it came to memory management. They just assumed the operating system would take care of it and the machine ran slower and slower until it crashed. (Remind you of Microsoft?)<\/p>\n\n\n\n<p>I ranted and ragged for years that the academics on the C++ standards committee needed to &#8220;fix new.&#8221; I wanted it to keep track of each allocation by file and line and timestamp when a program was compiled with debug and to print out a nice list of all things left not freed when execution ended. The academics never got around to it. They were more focused on doing stupid things like mandating 2&#8217;s complement for integer storage when Unysis mainframes (the ones used by the IRS and many other large financial institutions) are 1&#8217;s complement.<\/p>\n\n\n\n<p>Industry got tired of waiting for academics to get a clue, it created <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\">AddressSanitizer<\/a>. It got rolled into GNU and many other compilers around the time of Ubuntu 12.04. You can read more about it <a href=\"https:\/\/gcc.gnu.org\/onlinedocs\/gcc-6.3.0\/gcc\/Instrumentation-Options.html\">here<\/a> and <a href=\"https:\/\/www.osc.edu\/resources\/getting_started\/howto\/howto_use_address_sanitizer\">here<\/a>. Some things you might want to keep handy for your CMake scripts.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Deja-Vu-Mono.ttf\" style=\"font-size:.875rem;font-family:Code-Pro-Deja-Vu-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\" CFLAGS += -fsanitize=address -fno-omit-frame-pointer\n CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer\n LDFLAGS += -fno-omit-frame-pointer -fsanitize=address\n ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 \n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\"> CFLAGS += -fsanitize=address -fno-omit-frame-pointer<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\"> CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\"> LDFLAGS += -fno-omit-frame-pointer -fsanitize=address<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\"> ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 <\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>When you have a very simple class like our ImplicitClass and NoFarHeap classes, take the defaults. <em>It&#8217;s best to be explicit about them as we were in NoFarHeap<\/em>. Everybody goes through that &#8220;I memorized the language standard&#8221; phase of coding, then they learn what it is to have a life and stop memorizing the language standard.<\/p>\n\n\n\n<p>Any time you have a class that dynamically allocates something which must be freed in the destructor <strong>be certain to delete the copy constructor!<\/strong> If you don&#8217;t you will end up with a dual delete\/free at runtime. If you think &#8220;smart pointers&#8221; will &#8220;solve&#8221; the issue for you <a href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/\">read this post<\/a>.<\/p>\n\n\n\n<p>Making your destructor virtual does make it easier for someone to use it as a base class passing all of the classes they derived from it around via a base class pointer. It also adds vtable entries and overhead to the class at run-time. Unless you are an application framework created in the early 1990s basing all of your objects off something like QObject so you can ensure object deletion . . . <strong>should you really be doing that<\/strong>? This is 2024. We shouldn&#8217;t be cheating like that anymore, not without a damned good reason. In the 1990s we had to because neither the language nor the industry had tools like AddressSanitizer.<\/p>\n\n\n\n<p>I&#8217;m not a fan of <a href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/smart-pointers\/\">Template Metaprogramming<\/a>, but it has its place. Most modern-ish C++ frameworks are going the route of making all containers templates so instead of having to use a QObject generic pointer the compiler spins up a customer container class for your object. Remember: STL == Standard Template Library.<\/p>\n\n\n\n<p>Above all else remember that a default destructor does nothing. It&#8217;s just a free of the memory within your class object, not anything it allocated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is that the default deconstructor does basically nothing. Near Heap allocations are reclaimed automatically when you return from a method\/function. For Far Heap objects all it does is free the allocation. It will not free any sub allocations. You have already been shown the code for the ImplicitClass so we will not &hellip; <a title=\"C++ \u2013 Defaults and Deletes \u2013 Pt. 3\" class=\"bnm-read-more\" href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/\"><span class=\"screen-reader-text\">C++ \u2013 Defaults and Deletes \u2013 Pt. 3<\/span>Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":6848,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1504],"class_list":["post-6866","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information-technology","tag-c","bnm-entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C++ \u2013 Defaults and Deletes \u2013 Pt. 3 &#8211; Logikal Blog<\/title>\n<meta name=\"description\" content=\"In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is . . .\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ \u2013 Defaults and Deletes \u2013 Pt. 3 &#8211; Logikal Blog\" \/>\n<meta property=\"og:description\" content=\"In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is . . .\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/\" \/>\n<meta property=\"og:site_name\" content=\"Logikal Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-07T17:18:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-08T22:42:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/cpp-icon.png\" \/>\n\t<meta property=\"og:image:width\" content=\"256\" \/>\n\t<meta property=\"og:image:height\" content=\"288\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"seasoned_geek\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"seasoned_geek\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/\"},\"author\":{\"name\":\"seasoned_geek\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"headline\":\"C++ \u2013 Defaults and Deletes \u2013 Pt. 3\",\"datePublished\":\"2024-02-07T17:18:02+00:00\",\"dateModified\":\"2024-02-08T22:42:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/\"},\"wordCount\":1159,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/cpp-icon.png\",\"keywords\":[\"C++\"],\"articleSection\":[\"Information Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/\",\"name\":\"C++ \u2013 Defaults and Deletes \u2013 Pt. 3 &#8211; Logikal Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/cpp-icon.png\",\"datePublished\":\"2024-02-07T17:18:02+00:00\",\"dateModified\":\"2024-02-08T22:42:41+00:00\",\"description\":\"In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is . . .\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/cpp-icon.png\",\"contentUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/02\\\/cpp-icon.png\",\"width\":256,\"height\":288,\"caption\":\"C++ image from icons-library.com\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/delete\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ \u2013 Defaults and Deletes \u2013 Pt. 3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#website\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/\",\"name\":\"Logikal Blog\",\"description\":\"For people with attention spans longer than a Tweet\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\",\"name\":\"seasoned_geek\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"caption\":\"seasoned_geek\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\"},\"description\":\"Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++\\\/Qt touchscreen\\\/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the \\\"Zinc It!\\\" book series for John Gordon Burke Publisher, Inc. A decade later he released a massive (nearly 800 pages) tome \\\"The Minimum You Need to Know to Be an OpenVMS Application Developer\\\" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there \\\"The Minimum You Need to Know\\\" book series was born. Three years later he wrote his first novel \\\"Infinite Exposure\\\" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of \\\"The Earth That Was\\\" trilogy: Infinite Exposure Lesedi - The Greatest Lie Ever Told John Smith - Last Known Survivor of the Microsoft Wars When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.\",\"sameAs\":[\"https:\\\/\\\/theminimumyouneedtoknow.com\"],\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/author\\\/seasoned_geek\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ \u2013 Defaults and Deletes \u2013 Pt. 3 &#8211; Logikal Blog","description":"In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is . . .","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/","og_locale":"en_US","og_type":"article","og_title":"C++ \u2013 Defaults and Deletes \u2013 Pt. 3 &#8211; Logikal Blog","og_description":"In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is . . .","og_url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/","og_site_name":"Logikal Blog","article_published_time":"2024-02-07T17:18:02+00:00","article_modified_time":"2024-02-08T22:42:41+00:00","og_image":[{"width":256,"height":288,"url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/cpp-icon.png","type":"image\/png"}],"author":"seasoned_geek","twitter_card":"summary_large_image","twitter_misc":{"Written by":"seasoned_geek","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#article","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/"},"author":{"name":"seasoned_geek","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"headline":"C++ \u2013 Defaults and Deletes \u2013 Pt. 3","datePublished":"2024-02-07T17:18:02+00:00","dateModified":"2024-02-08T22:42:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/"},"wordCount":1159,"commentCount":0,"publisher":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/cpp-icon.png","keywords":["C++"],"articleSection":["Information Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/","url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/","name":"C++ \u2013 Defaults and Deletes \u2013 Pt. 3 &#8211; Logikal Blog","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#primaryimage"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/cpp-icon.png","datePublished":"2024-02-07T17:18:02+00:00","dateModified":"2024-02-08T22:42:41+00:00","description":"In this installment for Defaults and Deletes we finish the code for the example program. So far, among the things you have learned is . . .","breadcrumb":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#primaryimage","url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/cpp-icon.png","contentUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/02\/cpp-icon.png","width":256,"height":288,"caption":"C++ image from icons-library.com"},{"@type":"BreadcrumbList","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/delete\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.logikalsolutions.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"C++ \u2013 Defaults and Deletes \u2013 Pt. 3"}]},{"@type":"WebSite","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#website","url":"https:\/\/www.logikalsolutions.com\/wordpress\/","name":"Logikal Blog","description":"For people with attention spans longer than a Tweet","publisher":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.logikalsolutions.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842","name":"seasoned_geek","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","url":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","caption":"seasoned_geek"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r"},"description":"Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++\/Qt touchscreen\/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the \"Zinc It!\" book series for John Gordon Burke Publisher, Inc. A decade later he released a massive (nearly 800 pages) tome \"The Minimum You Need to Know to Be an OpenVMS Application Developer\" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there \"The Minimum You Need to Know\" book series was born. Three years later he wrote his first novel \"Infinite Exposure\" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of \"The Earth That Was\" trilogy: Infinite Exposure Lesedi - The Greatest Lie Ever Told John Smith - Last Known Survivor of the Microsoft Wars When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.","sameAs":["https:\/\/theminimumyouneedtoknow.com"],"url":"https:\/\/www.logikalsolutions.com\/wordpress\/author\/seasoned_geek\/"}]}},"_links":{"self":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts\/6866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6866"}],"version-history":[{"count":0,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts\/6866\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media\/6848"}],"wp:attachment":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}