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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:45:26+00:00 2026-06-11T19:45:26+00:00

I have two questions about the following code. class cls{ int vi; public: cls(int

  • 0

I have two questions about the following code.

class cls{
    int vi;
    public:
        cls(int v=37) { vi=v; }
        friend int& f(cls);
};

int& f(cls c) { return c.vi; }

int main(){
    const cls d(15);
    f(d)=8;
    cout<<f(d);
    return 0;
}
  1. Why does it compile, since f(d) = 8 attemps to modify a const object?
  2. Why does it still print 15, even after removing the const attribute?
  • 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-11T19:45:27+00:00Added an answer on June 11, 2026 at 7:45 pm

    It is not modifying a const object as a copy of d is being made due to the argument of f() being passed by value and not by reference. This is also the reason that d is unchanged as it is not being modified.

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

Sidebar

Related Questions

I have two questions about the following code. 1. How to constructor the third
I have two questions about java.awt.Shape . Suppose I have two Shape s, shape1
So I have two questions about HashMap s in Java: What is the correct
I have two noobish questions about Flash, Actionscript, Flex etc. 1) With these technologies
I'm building this website and I have basically two questions about this page: http://sites.publishyours.com.br/silviamecozzi/pt/obra/deserto_das_palmas.php
So basically, I have two fast questions about kohana urls. 1) With default .htaccess
I've got some basic questions about C++. Consider the following code in which I
Hi I have a question about Batcher's odd-even-merge sort. I have the following code:
I used an interface and class similar to following: public interface IIdentity { int
I would like to know two things about the following code: HttpWebRequest objRequest =

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.