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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:14:13+00:00 2026-06-02T20:14:13+00:00

Please help to complete this execution of an assignment overloading function. Here is the

  • 0

Please help to complete this execution of an assignment overloading function.

Here is the instruction:

Assignment operator (=) which will copy the source string into the destination string. Note that size of the destination needs to be adjusted to be the same as the source.

Both addition (+) and assignment (=) operators need to be capable of cascaded operations. This means String3 = String1 + String2, or String1 = String2 = String3 should work.

Here is my .cpp file:

 int MyString::Length()
 {
       int counter(0);

       while(String[counter] != '\0')
       {
            counter ++;
       }
     return (counter);
 }

MyString& MyString::operator=(const MyString& rhs)
{

        if(this != &rhs)
        {

                delete [] String;
                String = new char[rhs.Length()];

             for(int i = 0; i <rhs.Length()+1 ; i++)
            {       
                  String[i] = rhs.String[i];
            }       


        }
        return *this;

}

It is called in the main.cpp file by:

String1=String2=String3;

I feel as though I am missing something.Help!!

  • 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-02T20:14:15+00:00Added an answer on June 2, 2026 at 8:14 pm

    I suppose String is a char*. Perhaps then, Size, which is the new length, needs to be set to the length of rhs, which is the new string. So it should be rhs.Size, and not perhaps this->Size, which is likely to be the case. Note that the terminating null character should be considered in the char array size as well.

    After that you can enter the loop, once again take care of all the characters, and the terminating null character. Given we do not know what counter is and assuming it is the new string length without the null character (hence, + 1 accounting for it), I suppose there aren’t any problems with the loop.

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

Sidebar

Related Questions

I want to make this script to work as LIVE() function. Please help me!
Could you please help me in highlighting the typed words in the auto complete
Please help me on this. I am doing this on Fedora 16. My virtual
Please help! Background info I have a WPF application which accesses a SQL Server
Please help, I am stuck here --- irb> a = line of text\n line
Note - I will really appreciate a quick and complete answer to this question.
please help me resolve this problem: There is an ambient MSMQ transaction. I'm trying
I was trying to answer this questions If anyone can help please A multiprogramming
Please help me ! I have a problem in Crystal Report at visual studio::
Please help!!! I am using gesture recognizer to move my UIView. During moving I

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.