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

  • SEARCH
  • Home
  • 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 8154013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:12:23+00:00 2026-06-06T16:12:23+00:00

I apologize if the title sounds abstruse, let me make that simple with an

  • 0

I apologize if the title sounds abstruse, let me make that simple with an example :

class A
{
public:
    A(int *flag) : flag_(flag) {}
    void foo();
private:
    void bar();
    int *flag_;
};

The question is: can I prevent this class from changing the value pointed to by flag_?

Note : I’m thinking, maybe I want to write something like const int * flag_, but I do not want to make the value pointed to by flag “irrevocably” constant. In my case, this value is the value of some member variable of some other class, which can be changed.

Thanks for your insights!

  • 1 1 Answer
  • 0 Views
  • 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-06-06T16:12:24+00:00Added an answer on June 6, 2026 at 4:12 pm

    const int *flag_; will not modify the constness of the actual variable passed in, it just defines how flag_ can be used. Whatever you pass into A’s constructor will not have its constness changed. const isn’t a runtime change, it’s merely syntax to prevent the coder from accidentally modifying a value. You can do yourself one better and make it const int *const flag_; which will prevent A from modifying *flag_ AND flag_ won’t be reassignable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize that the title may not make sense, so let me describe my
I couldn't think of a decent title, so let me first apologize for that.
I apologize for the vague title. I am attempting to write a query that
I apologize for vague title so let me explain. Suppose you have a page
I know the title might not be clear and I apologize about that. so
Ok, maybe I'm missing something really simple and I apologize if that's the case,
I realize that the title may be somewhat confusing, so I apologize. Basically, this
First, I wish to apologize if the title is vague, the question is hard
In advance, I apologize if the question title may not be be convenient. I'm
First of all, I have to apologize for not having a better title. Feel

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.