{"id":6811,"date":"2024-01-27T14:25:56","date_gmt":"2024-01-27T20:25:56","guid":{"rendered":"https:\/\/www.logikalsolutions.com\/wordpress\/?p=6811"},"modified":"2024-01-27T14:25:58","modified_gmt":"2024-01-27T20:25:58","slug":"const","status":"publish","type":"post","link":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/","title":{"rendered":"C++ \u2014 That Const Thing"},"content":{"rendered":"\n<p>Const is what makes C++ great. Const is what makes C++ too horrible to work with. <\/p>\n\n\n\n<p>Developers who read those &#8220;Effective&#8221; books on C++ really screw the pooch. The developers working on the Qt library who hide everything anyone would want to override inside a &#8220;private&#8221; class only documented in the source file for the actual class and buried behind a macro passing most everything to it as const make the &#8220;screw the pooch&#8221; developers seem like they almost know what they are doing.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"419\" height=\"121\" src=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/q-d-001.png\" alt=\"\" class=\"wp-image-6819\" srcset=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/q-d-001.png 419w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/q-d-001-300x87.png 300w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"477\" height=\"76\" src=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/q_d-002.png\" alt=\"\" class=\"wp-image-6820\" srcset=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/q_d-002.png 477w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/q_d-002-300x48.png 300w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><\/figure>\n<\/div>\n\n\n<p>Honestly, if you are pulling shit like that in production code someone should definitely break both your thumbs if not worse. Libraries which pull shit like this are quickly being purged from the marketplace.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Academics vs. Production Coders<\/h2>\n\n\n\n<p>Academics think stuff like the above is &#8220;good and proper.&#8221; They&#8217;ve never written a line of production code in their lives. They definitely have never written production systems that <em>went over 10 years without any modifications despite drastic changes to the business model<\/em>. I have. It was written in the very early 1990s and is still in production today.<\/p>\n\n\n\n<p><strong>Not one of you writes code forward thinking and good enough to be placed in a private class.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Plymorphism<\/h3>\n\n\n\n<p>Nobody does. It is the pinnacle of arrogance to place the actual functionality inside a hidden private class leaving the exposed class as just a wrapper. You completely violate the fundamental tenant of OOP. <a href=\"https:\/\/www.geeksforgeeks.org\/cpp-polymorphism\/\">Polymorphism<\/a>.<\/p>\n\n\n\n<p>When you bury the actual functionality inside a hidden private class passing const parameters you make it impossible to cleanly alter the class via inheritance. When you do it with methods that are not virtual one cannot even use <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/override\">override<\/a> to fix your problem. If you are passing a base class pointer around you get the base class implementation, no matter what the actual object is. Doesn&#8217;t that suck?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Realities of Regulation<\/h2>\n\n\n\n<p>Academics and those who never studied actual Computer Science always design code like they are developing software for Walmart or some Internet startup. If there is a massive breach because they didn&#8217;t consider security, who cares? Nobody has gone to prison for that. The corporation will just buy N-months of credit monitoring and life will go on.<\/p>\n\n\n\n<p>Those of us who have worked in the military contractor\/black-ops\/clearance required projects world and the FDA regulated world know that is not reality. In extreme cases you both go to prison and get <a href=\"https:\/\/arstechnica.com\/science\/2024\/01\/convicted-fraudster-elizabeth-holmes-barred-from-federal-health-programs\/\">barred from federal health programs<\/a>. That&#8217;s right, she can get neither Medicare nor Medicaid. If she&#8217;s dead broke, when she gets sick she dies. You can even be <a href=\"https:\/\/www.theguardian.com\/us-news\/2024\/jan\/24\/martin-shkreli-drug-industry-ban\">banned from the industry like Pharma-bro<\/a>.<\/p>\n\n\n\n<p>Yes children, your OpenSource hack-on-the-fly code finds its way into these systems. It causes deaths, failures, and breaches because you would rather have fun hacking on the fly than apply actual Software Engineering. (Agile is <em>not<\/em> Software Engineering!)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Real Life Situation &#8211; LIMS<\/h3>\n\n\n\n<p>Yeah, I was going to give you a military example, but I can do it all in one. There is one class of software on which all lives depend: LIMS (Laboratory Information Management Systems) Every pharmaceutical and most defense contractors have them. Besides test composition\/results and a bunch of other geekly things, one of the core assets held are MSDS (<a href=\"https:\/\/www.sciencedirect.com\/topics\/pharmacology-toxicology-and-pharmaceutical-science\/material-safety-data-sheet\">Material Safety Data Sheet<\/a>) records. Many factories just have the paper sheets instead of a LIMS.<\/p>\n\n\n\n<p>Prior to any chemical compound becoming the next <a href=\"https:\/\/www.ozempic.com\/\">Ozempic<\/a> or a treatment for chemical\/biological weapons exposure, it starts out in a lab. An MSDS must exist for it, but your access to any content other than the &#8220;Hazards&#8221; section is restricted by your clearance\/employee role. Any chemical you can buy at a big box store, Pledge, Pine-Sol, ACT Flouride, etc. has a fully public MSDS. The antidotes for chemical\/biological weapons will never have fully public MSDS.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How Do You Deal With It?<\/h4>\n\n\n\n<p>Take this <a href=\"https:\/\/www.grandviewresearch.com\/industry-analysis\/laboratory-information-management-system-lims-market\">LIMS market size report<\/a> with a grain of salt. They are measuring &#8220;new sales&#8221; with that $2.3 Billion. Many companies rolled their own prior to canned packages becoming available. When I did a project in the 1980s for NutraSweet R&amp;D they had purchased VG LIMS. The labs have changed hands, but odds are they are still running that system. Once you get a LIMS system you hire people to maintain it and run the thing until you can no longer find hardware to run it on. You need all of the lab history in case you are sued. Just look at <a href=\"https:\/\/www.msn.com\/en-us\/money\/companies\/bayer-ordered-to-pay-225-billion-in-latest-roundup-trial\/ar-BB1hk7mE\">the Bayer Round-Up trials<\/a>. You need to keep that stuff forever. You also need to replicate point-in-time security levels. Yes, Dr. Susan has access to the information today in 2023, but did Dr. Susan have access to it on December 13th, 2013? (Leak\/breach tracing requirement.)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Details<\/h4>\n\n\n\n<p>Let us say we are going to use the above TextEdit to display the various text blocks of an MSDS on the screen. Those who&#8217;ve never worked on the real world on production systems will try to put all of the security and editing <em>in front of<\/em> the setPlainText() call. That&#8217;s a security breach waiting to happen. Dictator Xi thanks you for providing China with access to all of this advanced Western Technology.<\/p>\n\n\n\n<p>It needs to be inside of the setPlainText() call. That needs to make the determination, based on the user security level, which characters to replace with ASCII block characters. Your derived class needs to munge the data up based on the user. Why here? This is a one and done. No matter where you use the method it will call the security subroutine, blotting out what should not be visible for this user. Editing in front of the call means you have to do it and test it each and every place data is displayed. The fool who used const and buried all functionality in a hidden private class really screwed the pooch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Some Const Basics<\/h2>\n\n\n\n<p>Many people think the above doesn&#8217;t belong in a technical discussion. Someone should warn them about thinking. You write software based on your life experience. When you are not formally trained and don&#8217;t have decades of experience, you make some damned short-sighted decisions. That&#8217;s where const is dangerous. People in the above group are telling you to use const everywhere. When you work on a library claiming to have some OpenSource aspect to it, you need to make good decisions not perpetuate design flaws.<\/p>\n\n\n\n<p><strong>Don&#8217;t use const to define your interface if there is a <em>single<\/em> use case that would need to modify the variable.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The code<\/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=\"\/*\n * ConstThings.cpp\n *\n *  Created on: Jan 27, 2024\n *      Author: roland\n *\/\n#include &lt;iostream&gt;\n#include &quot;config.h&quot;\n#include &quot;mytriangle.h&quot;\n\nint main(int argc, char **argv) {\n\tstd::cout &lt;&lt; &quot;ConstThings Example&quot; &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;Version &quot; &lt;&lt; ConstThings_VERSION_MAJOR &lt;&lt; &quot;.&quot; &lt;&lt; ConstThings_VERSION_MINOR &lt;&lt; std::endl;\n\n\tdouble a_base {3.678};\n\tdouble a_height {4.321};\n\n\t\/*\n\t * Normal non-const pointer to non-const variable\n\t *\/\n\n\tdouble *a_ptr { &amp;a_base };\n\n\ta_ptr = &amp;a_height;\t\t\t\/\/ can be re-assigned\n\t*a_ptr = 6.234;\t\t\t\t\/\/ value of target variable can be re-assigned.\n\n\tstd::cout &lt;&lt; &quot;value of a_height: &quot; &lt;&lt; a_height &lt;&lt; std::endl;\n\n\t\/*\n\t * Placing const after the * means pointer is const.\n\t * You can change the value at the destination but you cannot change\n\t * where this pointer points.\n\t *\/\n\tdouble* const c_ptr { &amp;a_base };\n\t*c_ptr = 8.765;\n\n\tstd::cout &lt;&lt; &quot;value of a_base: &quot; &lt;&lt; a_base &lt;&lt; std::endl;\n\n\n\t\/*\n\t * Placing const before the pointer type declaration means a pointer to\n\t * a const variable. A non-const pointer cannot point to a const variable.\n\t *\n\t * Yes, the standards committee really got this backwards!\n\t *\n\t * If you attempt to assign the address of either const double to d_ptr\n\t * it would not compile because you would be casting away the const.\n\t *\n\t *\/\n\tconst double b_base {8.32};\t\t\/\/ d_ptr cannot point to either of these\n\tconst double b_height {2.4};\n\n\tconst double* b_ptr {&amp;b_base};\n\n\tstd::cout &lt;&lt; &quot;value *b_ptr: &quot; &lt;&lt; *b_ptr &lt;&lt; std::endl;\n\n\tb_ptr = &amp;b_height;\n\tstd::cout &lt;&lt; &quot;value *b_ptr after re-pointing: &quot; &lt;&lt; *b_ptr &lt;&lt; std::endl;\n\n\t\/*\n\t * a const pointer to a const value. All you can do is look at it.\n\t *\/\n\tconst double* const cant_change_nothing {&amp;b_base};\n\n\t\/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\t * It's almost the same for objects\n\t *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\t *\/\n\n\tMyTriangle mt( 3.0, 4.0);\n\n\tstd::cout &lt;&lt; &quot;area of mt: &quot; &lt;&lt; mt.area() &lt;&lt; std::endl;\n\n\tmt.setBase( 6.432);\n\tmt.setHeight( 2.345);\n\n\tstd::cout &lt;&lt; &quot;area of mt after changes: &quot; &lt;&lt; mt.area() &lt;&lt; std::endl;\n\n\t\/*\n\t * const pointer to non-const variable\n\t *\/\n\tMyTriangle* const mt_ptr {&amp;mt};\n\n\tmt_ptr-&gt;setBase(8.765);\n\tmt_ptr-&gt;setHeight(1.234);\n\n\tstd::cout &lt;&lt; &quot;base: &quot; &lt;&lt; mt_ptr-&gt;base() &lt;&lt; &quot;  height: &quot; &lt;&lt; mt_ptr-&gt;height()\n\t\t\t&lt;&lt; &quot;  area: &quot; &lt;&lt; mt_ptr-&gt;area() &lt;&lt; std::endl;\n\n\t\/*\n\t * const pointer to a const variable\n\t *\/\n\tconst MyTriangle mt2(4,6);\n\tconst MyTriangle* mt2_ptr {&amp;mt2};\n\n\tstd::cout &lt;&lt; &quot;mt2 base: &quot; &lt;&lt; mt2_ptr-&gt;base() &lt;&lt; &quot;  height: &quot;\n\t\t\t&lt;&lt; mt2_ptr-&gt;height() &lt;&lt; &quot;  area: &quot; &lt;&lt; mt2_ptr-&gt;area() &lt;&lt; std::endl;\n\n\t\/*\n\t * const pointer to const variable.\n\t *\n\t * You can only use methods which have been flagged as const!!!\n\t *\n\t * Try taking const off the methods that simply return values and this won't\n\t * compile.\n\t *\/\n\tconst MyTriangle* const mt3_ptr {&amp;mt2};\n\n\tstd::cout &lt;&lt; &quot;mt3_ptr base: &quot; &lt;&lt; mt3_ptr-&gt;base()\n\t\t\t&lt;&lt; &quot;  height: &quot; &lt;&lt; mt3_ptr-&gt;height()\n\t\t\t&lt;&lt; &quot;  area:  &quot; &lt;&lt; mt3_ptr-&gt;area() &lt;&lt; std::endl;\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: #6B737C\">\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> * ConstThings.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *  Created on: Jan 27, 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;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 style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;mytriangle.h&quot;<\/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;ConstThings Example&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\"> ConstThings_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\"> ConstThings_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>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> a_base {<\/span><span style=\"color: #F8F8F8\">3.678<\/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\"> a_height {<\/span><span style=\"color: #F8F8F8\">4.321<\/span><span style=\"color: #B392F0\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * Normal non-const pointer to non-const variable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">a_ptr { <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">a_base };<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\ta_ptr <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">a_height;<\/span><span style=\"color: #6B737C\">\t\t\t\/\/ can be re-assigned<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">a_ptr <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">6.234<\/span><span style=\"color: #B392F0\">;<\/span><span style=\"color: #6B737C\">\t\t\t\t\/\/ value of target variable can be re-assigned.<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;value of a_height: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> a_height <\/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\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * Placing const after the * means pointer is const.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * You can change the value at the destination but you cannot change<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * where this pointer points.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">double*<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> c_ptr { <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">a_base };<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">c_ptr <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">8.765<\/span><span style=\"color: #B392F0\">;<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;value of a_base: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> a_base <\/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>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * Placing const before the pointer type declaration means a pointer to<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * a const variable. A non-const pointer cannot point to a const variable.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * Yes, the standards committee really got this backwards!<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * If you attempt to assign the address of either const double to d_ptr<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * it would not compile because you would be casting away the const.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> b_base {<\/span><span style=\"color: #F8F8F8\">8.32<\/span><span style=\"color: #B392F0\">};<\/span><span style=\"color: #6B737C\">\t\t\/\/ d_ptr cannot point to either of these<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> b_height {<\/span><span style=\"color: #F8F8F8\">2.4<\/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\">const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">double*<\/span><span style=\"color: #B392F0\"> b_ptr {<\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">b_base};<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;value *b_ptr: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">b_ptr <\/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\">\tb_ptr <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">b_height;<\/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;value *b_ptr after re-pointing: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\">b_ptr <\/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\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * a const pointer to a const value. All you can do is look at it.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">double*<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> cant_change_nothing {<\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">b_base};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t\/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * It&#39;s almost the same for objects<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tMyTriangle mt( <\/span><span style=\"color: #F8F8F8\">3.0<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">4.0<\/span><span style=\"color: #B392F0\">);<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;area of mt: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">area() <\/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: #79B8FF\">mt<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">setBase( <\/span><span style=\"color: #F8F8F8\">6.432<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #79B8FF\">mt<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">setHeight( <\/span><span style=\"color: #F8F8F8\">2.345<\/span><span style=\"color: #B392F0\">);<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;area of mt after changes: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">area() <\/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\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * const pointer to non-const variable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tMyTriangle<\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> mt_ptr {<\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">mt};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #79B8FF\">mt_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">setBase(<\/span><span style=\"color: #F8F8F8\">8.765<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #79B8FF\">mt_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">setHeight(<\/span><span style=\"color: #F8F8F8\">1.234<\/span><span style=\"color: #B392F0\">);<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;base: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">base() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  height: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">height()<\/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;  area: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">area() <\/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\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * const pointer to a const variable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> MyTriangle mt2(<\/span><span style=\"color: #F8F8F8\">4<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #F8F8F8\">6<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> MyTriangle<\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\"> mt2_ptr {<\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">mt2};<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;mt2 base: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt2_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">base() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  height: &quot;<\/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: #79B8FF\">mt2_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">height() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  area: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt2_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">area() <\/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\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * const pointer to const variable.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * You can only use methods which have been flagged as const!!!<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * Try taking const off the methods that simply return values and this won&#39;t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t * compile.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">\t *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> MyTriangle<\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> mt3_ptr {<\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">mt2};<\/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\"> <\/span><span style=\"color: #FFAB70\">&quot;mt3_ptr base: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt3_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">base()<\/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;  height: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt3_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">height()<\/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;  area:  &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">mt3_ptr<\/span><span style=\"color: #BBBBBB\">-&gt;<\/span><span style=\"color: #B392F0\">area() <\/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 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<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 * mytriangle.cpp\n *\n *  Created on: Jan 27, 2024\n *      Author: roland\n *\/\n\n#include &quot;mytriangle.h&quot;\n\nMyTriangle::MyTriangle()\n{\n}\n\nMyTriangle::MyTriangle(double base, double height) :\n\tm_base{ base } ,\n\tm_height{ height }\n{\n}\n\nMyTriangle::~MyTriangle()\n{\n}\n\ndouble MyTriangle::area() const\n{\n\treturn (ONE_HALF * m_base * m_height);\n}\n\ndouble MyTriangle::base() const\n{\n\treturn (m_base);\n}\n\ndouble MyTriangle::height() const\n{\n\treturn (m_height);\n}\n\nvoid MyTriangle::setHeight(double height)\n{\n\tm_height = height;\n}\n\nvoid MyTriangle::setBase(double base)\n{\n\tm_base = base;\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\"> * mytriangle.cpp<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *  Created on: Jan 27, 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;mytriangle.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">MyTriangle()<\/span><\/span>\n<span class=\"line\"><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: #B392F0\">MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">MyTriangle(<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> base<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> height) :<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tm_base{ base } <\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tm_height{ height }<\/span><\/span>\n<span class=\"line\"><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: #B392F0\">MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #F97583\">~<\/span><span style=\"color: #B392F0\">MyTriangle()<\/span><\/span>\n<span class=\"line\"><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\">double<\/span><span style=\"color: #B392F0\"> MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">area() <\/span><span style=\"color: #F97583\">const<\/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\"> (ONE_HALF <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\"> m_base <\/span><span style=\"color: #F97583\">*<\/span><span style=\"color: #B392F0\"> m_height);<\/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\"> MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">base() <\/span><span style=\"color: #F97583\">const<\/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_base);<\/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\"> MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">height() <\/span><span style=\"color: #F97583\">const<\/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_height);<\/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\"> MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">setHeight(<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> height)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tm_height <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> height;<\/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\"> MyTriangle<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">setBase(<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> base)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tm_base <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> base;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\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 * mytriangle.h\n *\n *  Created on: Jan 27, 2024\n *      Author: roland\n *\/\n\n#ifndef MYTRIANGLE_H_\n#define MYTRIANGLE_H_\n\nclass MyTriangle\n{\npublic:\n\tMyTriangle();\n\tMyTriangle(double base, double height);\n\tvirtual ~MyTriangle();\n\n\tconst double ONE_HALF {0.5};\n\n\tdouble area() const;  \/\/ const allows methods to be used when object is const\n\tdouble base() const;\n\tdouble height() const;\n\n\tvoid setBase( double b);\n\tvoid setHeight( double h);\nprivate:\n\tdouble m_base {0};\n\tdouble m_height {0};\n};\n\n#endif \/* MYTRIANGLE_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\"> * mytriangle.h<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"> *  Created on: Jan 27, 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\"> MYTRIANGLE_H_<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#define<\/span><span style=\"color: #B392F0\"> MYTRIANGLE_H_<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">class<\/span><span style=\"color: #B392F0\"> MyTriangle<\/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\">\tMyTriangle();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tMyTriangle(<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> base<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> height);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">virtual<\/span><span style=\"color: #B392F0\"> ~MyTriangle();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> ONE_HALF {<\/span><span style=\"color: #F8F8F8\">0.5<\/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\">double<\/span><span style=\"color: #B392F0\"> area() <\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\">;<\/span><span style=\"color: #6B737C\">  \/\/ const allows methods to be used when object is const<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> base() <\/span><span style=\"color: #F97583\">const<\/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\"> height() <\/span><span style=\"color: #F97583\">const<\/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\">void<\/span><span style=\"color: #B392F0\"> setBase( <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> b);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> setHeight( <\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\"> h);<\/span><\/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\">double<\/span><span style=\"color: #B392F0\"> m_base {<\/span><span style=\"color: #F8F8F8\">0<\/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\"> m_height {<\/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>\n<span class=\"line\"><span style=\"color: #F97583\">#endif<\/span><span style=\"color: #6B737C\"> \/* MYTRIANGLE_H_ *\/<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\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=\"cmake_minimum_required(VERSION 3.10)\n\n# Set some basic project attributes\nproject (ConstThings\n\tVERSION 0.1\n\tDESCRIPTION &quot;ConstThings example&quot;)\n\n# This project will output an executable file\nadd_executable(${PROJECT_NAME} ConstThings.cpp mytriangle.cpp mytriangle.h)\n\n# Create a simple configuration header\nconfigure_file(config.h.in config.h)\n\n# Include the configuration header in the build\ntarget_include_directories(${PROJECT_NAME} PUBLIC &quot;${PROJECT_BINARY_DIR}&quot;)\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\">cmake_minimum_required<\/span><span style=\"color: #B392F0\">(VERSION 3.10)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># Set some basic project attributes<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">project<\/span><span style=\"color: #B392F0\"> (ConstThings<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tVERSION 0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tDESCRIPTION <\/span><span style=\"color: #9DB1C5\">&quot;ConstThings example&quot;<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># This project will output an executable file<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">add_executable<\/span><span style=\"color: #B392F0\">(${PROJECT_NAME} ConstThings.cpp mytriangle.cpp mytriangle.h)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># Create a simple configuration header<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">configure_file<\/span><span style=\"color: #B392F0\">(config.h.in config.h)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># Include the configuration header in the build<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">target_include_directories<\/span><span style=\"color: #B392F0\">(${PROJECT_NAME} PUBLIC <\/span><span style=\"color: #9DB1C5\">&quot;${PROJECT_BINARY_DIR}&quot;<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">ConstThings Example<br \/>Version 0.1<br \/>value of a_height: 6.234<br \/>value of a_base: 8.765<br \/>value *b_ptr: 8.32<br \/>value *b_ptr after re-pointing: 2.4<br \/>area of mt: 6<br \/>area of mt after changes: 7.54152<br \/>base: 8.765  height: 1.234  area: 5.40801<br \/>mt2 base: 4  height: 6  area: 12<br \/>mt3_ptr base: 4  height: 6  area:  12<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Discussion<\/h2>\n\n\n\n<p>I used Mint Linux and Eclipse to create this code. Most of what you need to know is in the comments. That Agile mantra of &#8220;if the code is properly written it doesn&#8217;t need comments&#8221; is <em>complete<\/em> bullshit. Those losers don&#8217;t have systems that have been in production over 30 years, I do.<\/p>\n\n\n\n<p>Just how many of you bother to put const at the end of your class methods which are little more than &#8220;getters?&#8221; Your classes won&#8217;t work if the instance is declared const and someone just wants to print the values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to Use Const<\/h2>\n\n\n\n<p>Only declare function\/method parameters const if you can envision <em>every<\/em> use case. Most of you can&#8217;t. How many of you thought about having to have redacted text? The knee-jerk argument of &#8220;create your own class with a setSecuredText() method doesn&#8217;t get rid of the ticking time bomb. All it takes is one new developer and one new QA person for the setPlainText() method to get used in production because there is no way to hide it. Supreme Leader Putin thanks you for access to that information. Dictator Xi has now taken the formula for your wonder drug that cures all forms of cancer. China will be shipping it before your employer who actually paid for the research to discover it.<\/p>\n\n\n\n<p>Like Agile before it, const has been hurled at bad programmers trying to make them more productive. Those &#8220;effective&#8221; and other C++ books tell you to make everything const, they are wrong. They are tying to stop the incompetent from shooting themselves in the foot and both kneecaps while introducing massive architectural flaws.<\/p>\n\n\n\n<p>Go ahead. Try to inherit from that class adding a setSecuredText() call __and__ blocking the setPlainText(). You end up having to pull in a ton of their configuration macros, creating a shell wrapper class containing a hidden instance of this class, then pray it works with the next release.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Const is what makes C++ great. Const is what makes C++ too horrible to work with. Developers who read those &#8220;Effective&#8221; books on C++ really screw the pooch. The developers working on the Qt library who hide everything anyone would want to override inside a &#8220;private&#8221; class only documented in the source file for the actual class and buried behind a macro passing most everything to it as const make the &#8220;screw the pooch&#8221; developers &hellip; <a title=\"C++ \u2014 That Const Thing\" class=\"bnm-read-more\" href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/\"><span class=\"screen-reader-text\">C++ \u2014 That Const Thing<\/span>Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":6812,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1549,1274,1504,159,2198],"class_list":["post-6811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information-technology","tag-agilesucks","tag-agile","tag-c","tag-qt","tag-vg-lims","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++ \u2014 That Const Thing &#8211; Logikal Blog<\/title>\n<meta name=\"description\" content=\"Const is what makes C++ great. Const is what makes C++ too horrible to work with. Developers who read those &quot;Effective&quot; books on . . .\" \/>\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\/const\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ \u2014 That Const Thing &#8211; Logikal Blog\" \/>\n<meta property=\"og:description\" content=\"Const is what makes C++ great. Const is what makes C++ too horrible to work with. Developers who read those &quot;Effective&quot; books on . . .\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/\" \/>\n<meta property=\"og:site_name\" content=\"Logikal Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-27T20:25:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-27T20:25:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/pexels-photo-247506.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1880\" \/>\n\t<meta property=\"og:image:height\" content=\"1253\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\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\\\/const\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/\"},\"author\":{\"name\":\"seasoned_geek\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"headline\":\"C++ \u2014 That Const Thing\",\"datePublished\":\"2024-01-27T20:25:56+00:00\",\"dateModified\":\"2024-01-27T20:25:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/\"},\"wordCount\":1423,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/pexels-photo-247506.jpeg\",\"keywords\":[\"#AGILESucks\",\"Agile\",\"C++\",\"Qt\",\"VG LIMS\"],\"articleSection\":[\"Information Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/\",\"name\":\"C++ \u2014 That Const Thing &#8211; Logikal Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/pexels-photo-247506.jpeg\",\"datePublished\":\"2024-01-27T20:25:56+00:00\",\"dateModified\":\"2024-01-27T20:25:58+00:00\",\"description\":\"Const is what makes C++ great. Const is what makes C++ too horrible to work with. Developers who read those \\\"Effective\\\" books on . . .\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/pexels-photo-247506.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/pexels-photo-247506.jpeg\",\"width\":1880,\"height\":1253,\"caption\":\"Photo by Pixabay on Pexels.com\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/const\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ \u2014 That Const Thing\"}]},{\"@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++ \u2014 That Const Thing &#8211; Logikal Blog","description":"Const is what makes C++ great. Const is what makes C++ too horrible to work with. Developers who read those \"Effective\" books on . . .","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\/const\/","og_locale":"en_US","og_type":"article","og_title":"C++ \u2014 That Const Thing &#8211; Logikal Blog","og_description":"Const is what makes C++ great. Const is what makes C++ too horrible to work with. Developers who read those \"Effective\" books on . . .","og_url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/","og_site_name":"Logikal Blog","article_published_time":"2024-01-27T20:25:56+00:00","article_modified_time":"2024-01-27T20:25:58+00:00","og_image":[{"width":1880,"height":1253,"url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/pexels-photo-247506.jpeg","type":"image\/jpeg"}],"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\/const\/#article","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/"},"author":{"name":"seasoned_geek","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"headline":"C++ \u2014 That Const Thing","datePublished":"2024-01-27T20:25:56+00:00","dateModified":"2024-01-27T20:25:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/"},"wordCount":1423,"commentCount":3,"publisher":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/pexels-photo-247506.jpeg","keywords":["#AGILESucks","Agile","C++","Qt","VG LIMS"],"articleSection":["Information Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/","url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/","name":"C++ \u2014 That Const Thing &#8211; Logikal Blog","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/#primaryimage"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/pexels-photo-247506.jpeg","datePublished":"2024-01-27T20:25:56+00:00","dateModified":"2024-01-27T20:25:58+00:00","description":"Const is what makes C++ great. Const is what makes C++ too horrible to work with. Developers who read those \"Effective\" books on . . .","breadcrumb":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/#primaryimage","url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/pexels-photo-247506.jpeg","contentUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2024\/01\/pexels-photo-247506.jpeg","width":1880,"height":1253,"caption":"Photo by Pixabay on Pexels.com"},{"@type":"BreadcrumbList","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/const\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.logikalsolutions.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"C++ \u2014 That Const Thing"}]},{"@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\/6811","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=6811"}],"version-history":[{"count":0,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts\/6811\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media\/6812"}],"wp:attachment":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}