{"id":17,"date":"2007-10-12T22:48:28","date_gmt":"2007-10-13T05:48:28","guid":{"rendered":"http:\/\/squizion.net\/blog\/2007\/10\/12\/yet-another-way-to-shoot-yourself-in-the-foot-with-c\/"},"modified":"2008-07-08T23:09:37","modified_gmt":"2008-07-09T06:09:37","slug":"yet-another-way-to-shoot-yourself-in-the-foot-with-c","status":"publish","type":"post","link":"https:\/\/squizion.net\/blog\/2007\/10\/12\/yet-another-way-to-shoot-yourself-in-the-foot-with-c\/","title":{"rendered":"Yet another way to shoot yourself in the foot with C++"},"content":{"rendered":"<p>Found during pair programming (yes, I do it sometimes):<\/p>\n<p><code>  class Foo {<br \/>\n  public:<br \/>\n    Foo(bool in);<br \/>\n  ...<br \/>\n  };<\/p>\n<p>  ...<br \/>\n  Foo f = new Foo(true);<br \/>\n  ...<\/code><\/p>\n<p>Yikes. Didn&#8217;t expect that to get by the compiler. But it did. Without even a warning. The compiler was happy to turn &#8220;new Foo&#8221; into a boolean value and instantiate f, silently letting the memory leak away.<\/p>\n<p>This helps:<\/p>\n<p><code>  class Foo {<br \/>\n  public:<br \/>\n    explicit Foo(bool in);<br \/>\n  ...<br \/>\n  };<\/code><\/p>\n<p>But still. Ug. Single argument constructors in C++ are just evil. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Found during pair programming (yes, I do it sometimes): class Foo { public: Foo(bool in); &#8230; }; &#8230; Foo f = new Foo(true); &#8230; Yikes. Didn&#8217;t expect that to get by the compiler. But it did. Without even a warning. &hellip; <a href=\"https:\/\/squizion.net\/blog\/2007\/10\/12\/yet-another-way-to-shoot-yourself-in-the-foot-with-c\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/posts\/17"}],"collection":[{"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":0,"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"wp:attachment":[{"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/squizion.net\/blog\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}