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 8191923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:02:26+00:00 2026-06-07T04:02:26+00:00

I can declare foo(const T& var) so that I know var won’t be changed.

  • 0

I can declare foo(const T& var) so that I know var won’t be changed.

Equivalent format for pointer would be foo(const T* var)?

In the past I tried those, errors related to iterator/const_iterator irritated me and I just tended to use (T* var) without considering constness.

Are there a good doc for declaring function that enforces contents pointed by a pointer won’t change’?

  • 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-07T04:02:27+00:00Added an answer on June 7, 2026 at 4:02 am

    What you have is already a pointer that prohibits the pointee’s contents from changing. You can see this by using the “read backwards” rule:

    const T* var     <===== left to right from this read
    

    Reading backwards:

    var is a pointer to a T that is constant

    This is different from

    T* const var
    

    Which reads:

    var is a constant pointer to a T

    The difference here is that the constant is var, not the T; that means you can change the T by dereferencing var but you cannot change what var points to.

    And of course you can have both of the above at the same time:

    const T* const var
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i concatenate var names to declare new vars in javascript?: var foo
For throwing exceptions I know that you can declare/define the function with the implication
In PHP 5 I can declare a const value to a class: class config
In PHP, you can declare constants in two ways: With define keyword define('FOO', 1);
I have class foo that contains a std::auto_ptr member that I would like to
I understand that the correct way to declare a return type const is to
That is the question. Background: C# Params In C#, you can declare the last
In C# I can declare a static var in a class. E.g : to
Example: // can't forward declare with class Foo::Bar // actual class class Foo {
As most people who work with Sql Server know, you can declare a temporary

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.