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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:03:45+00:00 2026-06-02T23:03:45+00:00

The instructions are to: The MyString object should overload the following operators: 1)Parenthesis operator

  • 0

The instructions are to:

The MyString object should overload the following operators:

1)Parenthesis operator should be overloaded to replace the Set and Get functions of your previous assignment. Note that both instances should issue exit(1) upon violation of the string array bounaries.

My .cpp file where the functions are defined:

 // My original set function to replace the character at the index passed in with the character passed in

 void MyString::Set(int index, char b)
 {
    if(String[index] == '\0')
    {
            exit(1);
    }
    else
    {

            String[index] = b;
    }


 }
 //original get function to get the character of the index passed in as argument
 char MyString::Get(int i)
 {

    if( String[i] == '\0')
    {
            exit(1);
    }
    else
    {
            return String[i];

    }
 }

How do I possibly transform this into an overloaded () operator function?? The most I’ve gotten is:

 MyString& MyString::operator()(const int index, const char b)
 {
    if(String[index] == '\0')
    {
            exit(1);
    }
    else
    {

            String[index] = b;
    }


}


char& MyString::operator()(const int i)
{

    if( String[i] == '\0')
    {
            exit(1);
    }
    else
    {
            return String[i];

    }
}

What am I doing wrong?

  • 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-02T23:03:47+00:00Added an answer on June 2, 2026 at 11:03 pm

    Both Get and Set, and the two overloads of the () operator check for out of string error in an inappropriate (wrong!) manner. See, the i-th, or n-th element of a string can not be ‘\0’ if the string is not that long. If you try to read memory beyond the current string length, you will probably get a read access violation.

    Instead, you should check whether the given index is less then the string’s length, and if it is, then return the element. Otherwise, it is out of bounds.

    Another thing is that in the first overload of the () operator, you are using a string object to dereference a string array, which doesn’t make much sense. Also, b should be a character there, not a string, since you are setting only one element.

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

Sidebar

Related Questions

Followed instructions on Railscast but can't get server to start. It states the following
I'm following the instructions given on FB Developer, but I just can't get client
Following instructions from http://web2linux.com/installing-rails-3-on-ubuntu-10-04-lucid-lynx/ I get to the following line: rvm install 1.9.2 returns:
Tried following the instructions here: How to use Google app engine with my own
The Google Analytics setup instructions state: This tracking code snippet should be included in
I followed these instructions while trying to get remote debugging working with Delphi 2007.
I tried following the instructions here in order to create a static website on
I'm following the instructions here: http://blog.colinajohnston.com/scala-ide-200rc2-sbt-0112-lift-24-m5-now-with to setup eclipse with lift and sbt but
After following instructions on the emscripten wiki I have managed to compile a small
I follow the instructions on http://devcenter.heroku.com/articles/play to get my Play! (Java) app running on

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.