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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:45:09+00:00 2026-05-26T08:45:09+00:00

It was mentioned on stack overflow by a programmer that if you declare one

  • 0

It was mentioned on stack overflow by a programmer that if you declare one class function, for example:

operator++()

That for user-interface purposes (as the user naturally assumes its opposite should work), you should declare the other:

operator--()

Is there a link to an article that supports this? I wish to be able to reference it to other programmers.

I thought to add that, perhaps the suggestion is similar to the rule of 3, or the big 2.

In light of hostilefork’s answer, perhaps the opposite functions should be declared even in instances where even it doesn’t serve a purpose, but as private, so the user explicitly knows they cannot call that function? Or is that just being pedantic?

  • 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-26T08:45:09+00:00Added an answer on May 26, 2026 at 8:45 am

    One hard thing about C++ and operator overloading is that it can be sort of a pun. Overloading assignment created a bit of a pickle with auto_ptr, because code that tried to take “assignment” for granted was being surprised by assigning A to B and then finding immediately afterward that A != B.

    http://hostilefork.com/2009/07/10/smart-pointer-casting-study/

    I’ll point out if the following generalized code will compile, the users of a class will often assume it wouldn’t assert:

    SomeType foo (...);
    SomeType bar (foo);
    foo++; // let's say we know this is safe
    foo--; // then we'd generally hope this is safe also
    assert(foo == bar); // ...and this is true
    

    There’s no law enforcing that, though. Some people are vocal about it being bad to be tolerating such a a semantic free-for-all:

    http://yosefk.com/c++fqa/operator.html

    I’d lean toward saying it’s important to maintain some of those expectations. But there’s nothing wrong with not compiling a program where decrementing shouldn’t have meaning. Forward iterator was mentioned, perfect example.

    The foundational things that you get with languages tend to be very “mathematical” and “symmetric” (like an integer is unlikely to have addition but not subtraction). But I think that classes that are being tailored to solve specific problems trend toward getting greater value from being asymmetrical.

    It’s sort of the generality-vs-specificity thing. Think about an application that’s close to the user. They don’t want all things to be equally accessible…more common operations should be “easy” while infrequent operations can be marginalized a bit. Some of the most frustrating software is that which isn’t focused on the common case. Specialized classes that are there to solve a problem are often going to be a lot less symmetrical than General Purpose Language constructs or libraries.

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

Sidebar

Related Questions

I just saw this mentioned in Stack Overflow question Best WYSIWYG CSS editor and
I've seen other people mention several types of testing on Stack Overflow. The ones
On the Stackoverflow podcast this week, Jeff mentioned that in 2004 he wrote a
I like Stack Overflow's URLs - specifically the forms: /questions/{Id}/{Title} /users/{Id}/{Name} It's great because
Hello good Stack Overflow people, I do have a business problem and would like
Posting a stack overflow question on stackoverflow.com, how amusing :-) I'm running some recursive
Ok, I've read the Stack Overflow question 'What does it mean to program to
From Day One I was told that each third-party iOS app was perfectly sand-boxed
So I'm horribly confused by this error, other threads on Stack Overflow mention I
Does anybody know of a Scala wrapper for one of libraries mentioned in https://stackoverflow.com/questions/448643/statistical-library-for-java

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.