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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:22:32+00:00 2026-05-25T06:22:32+00:00

In The C++ programming language, at page 265, the author makes the following statement:

  • 0

In “The C++ programming language”, at page 265, the author makes the following statement:

Because of historical accident, the operators = (assignment), & (address-of), and , (sequencing;
§6.2.2) have predefined meanings when applied to class objects. These predefined meanings can
be made inaccessible to general users by making them private:

Then the following example is given:

class X {
private:
 void operator=(const X&);
 void operator&();
 void operator,(const X&);
 // ...
};

void f(X a, X b)
{
   a = b;  // error: operator= private
   &a;     // error: operator& private
   a,b;    // error: operator, private
}

I can’t quite understand what do these “error” comments refer to? Does that mean I should not define a function like f, or that all of the =, &, and , operators should be used according to the default way, and it is not necessary to redefine them?

  • 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-25T06:22:33+00:00Added an answer on May 25, 2026 at 6:22 am

    This example simply shows a way to prevent yourself or other developers of the code from using operators, which can be used without having been defined in the class, because they’re automatically generated (and have default meanings for the operations they represent).

    The author of the example meant, that if you try to assign b to a (in line a = b) it will cause an error, because the assignment operator is private in the class definition.

    Similar error occurs in case of address-of in the second line, and the comma operator in the third.

    Making default operators/constructors private if you know they’re not supposed to be used (or haven’t been implemented yet) is good, because one may accidentally use a very frequent operator like assignment or copy-constructor, being unaware that it’s default behavior conflicts with the class lifecycle. If such operator or constructor is made private at the very beginning of class design, the compiler will generate a compile-time error instead of performing a potentially dangerous operation without notice if the programmer accidentally uses the method.

    Think default assignment operator and member pointer: it will copy the pointer whereas you might want the object to be the owner of data. Then, after someone assigns one object to another without knowing that assignment is not implemented, you will end up with a double free error. Instead of that, if the operator is private, you’ll get a nice error and the code will not even compile, and you’ll know what’s going on.

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

Sidebar

Related Questions

In his The C++ Programming Language Stroustrup gives the following example for inc/dec overloading:
I was reading Douglas Crockford's web page, JavaScript: The World's Most Misunderstood Programming Language
Guys, I'm doing excercises from The C++ Programming Language 3rd ed. and on page
The go programming language has a page on code reviews using mq and it
The following question applies to any programming language I am working on a program
Quoting from Kernighan and Ritchie's 'The C Programming Language' Page 16 - #include<stdio.h> main()
On page 340 of the C++ Programming Language: Special Edition, Stroustrup writes... The semantic
The C++ Programming Language : Special Edition states on page 431 that... For every
I'm new to PHP programming language. Currently, i want to develop a page that
According to Wikipedia, on the Comparison of programming languages page, it says that F#

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.