{"id":14163,"date":"2023-07-19T07:03:32","date_gmt":"2023-07-19T07:03:32","guid":{"rendered":"https:\/\/blog.bachi.net\/?p=14163"},"modified":"2023-08-04T11:58:28","modified_gmt":"2023-08-04T11:58:28","slug":"c-const","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=14163","title":{"rendered":"C++ const"},"content":{"rendered":"<p><a href=\"https:\/\/blog.bachi.net\/?p=13668\">Const Correctness \/ C vs. C++ Differences<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/5973427\/error-passing-xxx-as-this-argument-of-xxx-discards-qualifiers\">error: passing xxx as &#8216;this&#8217; argument of xxx discards qualifiers<\/a><\/p>\n<blockquote><p> you&#8217;re calling a non-const member function on const object which is not allowed because non-const member functions make NO PROMISE not to modify the object<\/p><\/blockquote>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/751681\/what-is-the-meaning-of-const-at-the-end-of-a-member-function-declaration\">What is the meaning of &#8216;const&#8217; at the end of a member function declaration?<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/4674332\/declaring-a-const-instance-of-a-class\">declaring a const instance of a class<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nerror: passing xxx as 'this' argument of xxx discards qualifiers\r\nerror: passing \u2018const Foo\u2019 as \u2018this\u2019 argument of \u2018void Foo::bar()\u2019 discards qualifiers &#x5B;-fpermissive]\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nclass Foo {\r\n  public:\r\n    Foo() {};\r\n    virtual ~Foo() {};\r\n    \r\n    \/\/ must be const:\r\n    \/\/ void bar() const {};\r\n    void bar() {};\r\n};\r\n\r\nint\r\nmain(int argc, char *argv&#x5B;])\r\n{\r\n  const Foo foo;\r\n\r\n  foo.bar();\r\n\r\n  return 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Const Correctness \/ C vs. C++ Differences error: passing xxx as &#8216;this&#8217; argument of xxx discards qualifiers you&#8217;re calling a non-const member function on const object which is not allowed because non-const member functions make NO PROMISE not to modify the object What is the meaning of &#8216;const&#8217; at the end of a member function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14163","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/14163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14163"}],"version-history":[{"count":5,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/14163\/revisions"}],"predecessor-version":[{"id":14199,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/14163\/revisions\/14199"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}