Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 513653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:26:40+00:00 2026-05-13T07:26:40+00:00

I met two explanation of const member function class A{ public: … void f()

  • 0

I met two explanation of const member function

class A{
  public:
  ...
  void f() const {}
  ...
}
  1. it means it could only access constant members;
  2. it means it does not modify any members;

I think the second one is right. But why does the first one come out? Is there anything to be clarify?

Thanks!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:26:40+00:00Added an answer on May 13, 2026 at 7:26 am

    You can examine all class member values in a const member function, and in some cases you can even change the value of member variables. The first explanation is incorrect, I don’t know where it comes from. The second explanation is correct, but with a few exceptions.

    There are some exceptions to this rule. You can also change mutable variables in a const member function, for example a member variable declared like this:

    mutable float my_rank;
    

    You can also break const-correctness in a class by const_cast’ing a reference to yourself like this:

    Class* self = const_cast<Class*> (this);
    

    While technically allowed in C++, this is usually considered poor form because it throws away all of the const modifiers of your design. Don’t do this unless you actually have to, and if you find yourself having to do this quite a lot that suggests a problem with your design. The C++ FAQ covers this very well.

    Here are two references in case you want to do more reading:

    • Const-correctness (cprogramming.com)
    • Const correctness (C++ FAQ Lite)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am customizing N2CMS's database structure, and met with an issue. The two classes
I met a problem like this. class A have a list of class B.
I met an interesting issue about C#. I have code like below. List<Func<int>> actions
I have a requirement in my application that I think can be met by
The two WWW-Authenticate additions Microsoft makes use of that I am currently aware of
I have two collections, and items that are added to one or the other
I have two custom ActionFilters on an action. In first of the actionfilters, I
I have two tables. Report and ReportData . ReportData has a constraint ReportID. How
In my application there have two Outlet, one is UItextfield and another is UIWebview,
Possible Duplicates: Why is there a special new and delete for arrays? ( POD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.