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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:33:34+00:00 2026-06-01T07:33:34+00:00

Can some body tell me the reason why we usually put const and &

  • 0

Can some body tell me the reason why we usually put const and & with some object which is passed in the constructor for example.

Book::Book(const Date &date);

The confusion that i have here is that usually & sign is used in the some function because the value is passed by reference and whatever changes happen to that variable in the function should reflect afterwards. But on the other hand const says that no assignment can be done to that variable.

If some body have some good idea about that please let me know the reason for that.

  • 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-01T07:33:35+00:00Added an answer on June 1, 2026 at 7:33 am

    This is done to avoid an unnecessary copy. Take, for example, the following code:

    Book::Book(Date date):
    date_(date)
    {
    }
    

    When you call this constructor it will copy date twice, once when you call the constructor, and once when you copy it into your member variable.

    If you do this:

    Book::Book(const Date &date):
    date_(date)
    {
    }
    

    date is only copied once. It is essentially just an optimisation.

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

Sidebar

Related Questions

Can some body tell me any alternative to store some information for a particular
Can some body tell me how a webpage content is sent to google translator
Can some body tell me the difference between timestamp(0) and timestamp(6) in Teradata
Can some body tell me what is the exact size of tab bar in
Can somebody tell me what does this mean? I'm going trough Java book and
For some reason I can't make valgrind work with my Cocoa apllication on OS
Can any body tell me how to handle events for System tray in windows.
Hi can some one tell me whats the wrong in the below code? Trying
Can any body tell me that how many maximum subgraphs of a graph can
Hi can any body tell me how to add the feature of In App

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.