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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:22:20+00:00 2026-06-14T03:22:20+00:00

At the present moment I am reading C++ 11 standard , in which (chapter

  • 0

At the present moment I am reading C++ 11 standard, in which (chapter 12)
among special member functions is mentioned ?copy? assignment operator.

I have already faced with operator=, which is simply assignment operator

My first guess was that it is used in statements like this:

Class_name instance_name1 = instance_name2;   

when an object is created and initialized simultaneously, I checked my assumption and got that this done by means of copy constructor(which was expected).

So, what for copy assignment operator is used, how to declare it and can you give me some example of its usage.
Thanks in advance!

  • 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-14T03:22:21+00:00Added an answer on June 14, 2026 at 3:22 am

    It’s defined in the standard, 12.8/17:

    A user-declared copy assignment operator X::operator= is a non-static
    non-template member function of class X with exactly one parameter of
    type X, X&, const X&, volatile X& or const volatile X&.

    So for example:

    struct X {
        int a;
        // an assignment operator which is not a copy assignment operator
        X &operator=(int rhs) { a = rhs; return *this; }
        // a copy assignment operator
        X &operator=(const X &rhs) { a = rhs.a; return *this; }
        // another copy assignment operator
        volatile X &operator=(const volatile X &rhs) volatile { 
            a = rhs.a; 
            return *this; 
        }
    };
    

    Assignment operators are used when you assign to an object. You might think that doesn’t say much, but your example code Class_name instance_name1 = instance_name2; doesn’t assign to an object, it initializes one. The difference is in the grammar of the language: in both cases the = symbol precedes something called an initializer-clause, but Class_name instance_name1 = instance_name2; is a definition, whereas instance_name1 = instance_name2; on its own after instance_name1 has been defined is an expression-statement containing an assignment-expression. Assignment-expressions use assignment operators, definitions use constructors.

    If the usual rules for overload resolution select an assignment operator that is a copy assignment operator, then that’s when a copy assignment operator is used:

    X x;
    x = 4; // uses non-copy assignment operator
    X y;
    y = x; // uses copy assignment operator
    

    The reason there’s a distinction between copy and non-copy assignment operators, is that if you declare a copy assignment operator, that suppresses the default copy assignment operator. If you declare any non-copy assignment operators, they don’t suppress the default copy assignment.

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

Sidebar

Related Questions

I have a page where I present a specific product (book, cd etc) which
I have a few p/invoked functions (but I'm rewriting my code at the moment
Okay, at the moment i have my domain's host file which was generated by
Present Scenario : I have a set of classes that all take a common
At present I have a TestNG project that calls a JBoss RESTEasy web service.
At present we have a denormalised database. ie Name|NameID|EmployeeID|EmployeeType I'm normalising the database to
I want to present an iPad game which is only playable in portrait mode
I would like to present a scenario where it would be nice to: have
At the moment, I am coding an Google Chrome extension (in Javascript) which interfaces
I have this working ok(ish) in my game at the moment, but i'm not

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.