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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:22+00:00 2026-05-27T18:45:22+00:00

The below is an exam question: /* 1 */ string s1 = FRED; /*

  • 0

The below is an exam question:

    /* 1 */ string s1 = "FRED";
    /* 2 */ string s2 = s1;
    /* 3 */ string s3 = "DERF";
    /* 4 */ s3 = s1;

For the second and the fourth lines above, name what type of statement that line is. Will
they call the same member function of class string? [5 marks]

So my answer:

  • Line 2 is initializing a new string object s2 using the copy constructor to copy over all the member variables from s1 into the s2.
  • Line 4 is also copying over all the member variables from s1 into s2, but it is overloading the assignment operator (operator=) to do so.

Therefore they both are calling 2 different member functions.

Is the above an acceptable answer? Is there anything I can add of do I have the wrong idea?

  • 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-05-27T18:45:23+00:00Added an answer on May 27, 2026 at 6:45 pm

    About your answer regarding Line #4

    You cannot be certain that it actually makes use of the copy constructor, and it absolutely shouldn’t.

    Why create a temporary object inside std::string::operator= when you could copy the data from s1 into s3 directly?

    What you wrote about operator= is correct, but leave out what you wrote about the copy-constructor there. There is no initialization of a new object, therefor no constructor should be called.


    You should also leave out the statement regarding making copies of all the member variables, that doesn’t have to be true.

    And when it comes to objects such as std::string there are pointers as members that aren’t copied, but the memory where they point are being copied into a new memory space (to be used by the destination object).


    Post OP edit of his/hers post..

    OP just changed his post deleting what I made a remark on in the first part of this post.

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

Sidebar

Related Questions

I ran across the question below in an old exam. My answers just feels
I'm attempting to solve the below exam question but I'm having difficulties with it.
I'm building a form to create an exam object that starts with 1 question,
Below is my current char* to hex string function. I wrote it as an
Below are lines from the c++ programming language template<class T > T sqrt(T );
I am busy preparing for exams, just doing some old exam papers. The question
I have a asp:dropdownlist, which shows below code when page renders <select id=ContactUs_ddlWhichProgrammes name=ContactUs$ddlWhichProgrammes>
I was confused about the wording of a particular exam question about hash tables.
I want to generate a string like the one mentioned below in C# code
I am having this problem in below code as my ArrayList both name and

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.