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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:22:01+00:00 2026-06-12T10:22:01+00:00

I have to write one new class with members something like class A {

  • 0

I have to write one new class with members something like

class A
{
    static int i;
    const int j;
    char * str;
    ...
    ...
};

Now I want to write assignment operator for it.

A& A::operator=(const A& rhs)
{
    if(this != rhs)
    {
        delete [] str;
        str = new char[strlen(rhs.str)+1];
        strcpy(str, rhs.str);
    }
    return * this;
}

Is it right? I shall ignore the static and const members(?).

  • 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-12T10:22:02+00:00Added an answer on June 12, 2026 at 10:22 am

    The assignment operator copies one object into another. Since all objects of the same type share the same static members, there’s no reason to copy the static members.

    const members are another matter. You can’t (well, shouldn’t) change them, but if two objects have different values for a const member, it might not be a good idea to copy one object into another; the const member won’t have the right value. That’s why the compiler doesn’t generate a copy assignment operator for classes that have const members. So you first have to be sure that copying such an object makes sense, even with the wrong value for the const members; and then ask yourself why it has const members if they don’t affect how it behaves.

    References too. (yes, there’s an echo in here)

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

Sidebar

Related Questions

I have a class A and write a subclass B. A has only one
I have a C program like the one below. I am trying to write
I have the following class and data members (plus irrelevant methods) I am new
I have to write integration test case for my one feature listing page and
I have one problem, I learn how work with socket and I write programm
I have two Data Centers, each one with replication factor 3. Will write with
I have the following simple class class base { public: int x; base &set(int
i have this code in one of my asp.net mvc views: <%Html.RenderFile(@C:\Members\newsletters\welcome.html);%> I have
I have a List <customClass >. The custom class contains two members that, together,
I have a program that I am trying to write that one row of

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.