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

The Archive Base Latest Questions

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

Possible Duplicate: Is it allowed to name the parameter in postfix operator ++? I

  • 0

Possible Duplicate:
Is it allowed to name the parameter in postfix operator ++?

I created an object to hold a list of objects that maintains the current position internally, so I thought this was a great place to overload the pre and post increment operators, which effectively increment this internal position with bounds checking.

What I noticed is, when you call ++ on the object, the argument is 0.

Test code:

#include <stdio.h>
class A {
public:
   A& operator++(int n) { printf("%d  ", n); return *this; }
};
int main() {
   A a;
   a++;
   a.operator++(0);
   a.operator++(1);
   a.operator++(10);
   return 0;
}

This returns 0 0 1 10. From what I understand, this is normal behavior. So, it has made me rethink how operator++ should work. Previously, I was simply calling ++ on my internal position variable if bounds checking passed. But this has the affect of incrementing by 1 no matter what the input argument is. Next, I though of using the += using the argument n as the right hand side, but as you’ll notice, simply calling ++ with no operators (as is customary), gives a zero and the position is not incremented.

Basically, is this something I should even worry about? If so, how do I detect if the user really wanted 0, or if the default behavior (a++) was intended and I should increment by 1?

  • 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-22T17:40:33+00:00Added an answer on May 22, 2026 at 5:40 pm

    You should just ignore the parameter.

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

Sidebar

Related Questions

Possible Duplicate: Define a generic that implements the + operator I am recently working
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
Possible Duplicate: C++ Comma Operator what is result of operator ',' by standard? Last
Possible Duplicate: Why is this not allowed in C++? Why is this not allowed
Possible Duplicate: Why are some operators in C++ only allowed to be overloaded as
Possible Duplicate: Why const parameters are not allowed in C# I am a C++
Possible Duplicate: What's Alternative to Singleton If I am not allowed to use the
Possible Duplicate: Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes)
Possible Duplicate: Why isn't the const qualifier working on pointer members on const objects?
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

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.