{"id":25,"date":"2008-07-02T01:41:29","date_gmt":"2008-07-02T00:41:29","guid":{"rendered":"http:\/\/entrian.com\/blog\/c-mfc-sanity-insanity\/"},"modified":"2021-07-01T07:13:43","modified_gmt":"2021-07-01T07:13:43","slug":"c-mfc-sanity-insanity","status":"publish","type":"post","link":"https:\/\/entrian.com\/blog\/c-mfc-sanity-insanity\/","title":{"rendered":"C++, MFC, sanity, insanity"},"content":{"rendered":"<p>One of the really nice things about C++ compared with C is the existence of constructors. In C, if you say:<\/p>\n<pre>struct\n{\n    int count;\n}\nthing;<\/pre>\n<p>then thing.count holds a random value until you set it to something. In C++, that doesn&#8217;t happen because any sane class has a constructor that sets the member variables to sensible default values:<\/p>\n<pre>class Thing\n{\n    Thing(void)\n    {\n        count = 0;\n    }\n    int count;\n};<\/pre>\n<p>You can&#8217;t create a Thing with a random count because the constructor gets called automatically.<\/p>\n<p>MFC is Microsoft&#8217;s C++ framework for Windows development. It&#8217;s very widely used, mature and stable. It has a class CRect to represent a rectangle. And does its default constructor set the coordinates to sensible default values? Does it hell. Does it even set them to known <strong>insane<\/strong> values, to immediately alert you when you forget to initialise them, or when you naturally assume that the default constructor is sane? Does it hell.<\/p>\n<p>Thank you whoever at Microsoft made that decision. You just cost me about 6 hours of my life.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the really nice things about C++ compared with C is the existence of constructors. In C, if you say: struct { int count; } thing; then thing.count holds a random value until you set it to something. In C++, that doesn&#8217;t happen because any sane class has a constructor that sets the member [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-30days"],"_links":{"self":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":1,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":1211,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions\/1211"}],"wp:attachment":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}