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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:54:19+00:00 2026-05-27T02:54:19+00:00

I am trying to deal with operator overloading at the first time, and I

  • 0

I am trying to deal with operator overloading at the first time, and I wrote this code to overload ++ operator to increment class variables i and x by one..
It does the job but the compiler showed these warnings:

Warning 1 warning C4620: no postfix form of ‘operator ++’ found for
type ‘tclass’, using prefix
form c:\users\ahmed\desktop\cppq\cppq\cppq.cpp 25

Warning 2 warning C4620: no postfix form of ‘operator ++’ found for
type ‘tclass’, using prefix
form c:\users\ahmed\desktop\cppq\cppq\cppq.cpp 26

This is my code:

class tclass{
public:
    int i,x;
    tclass(int dd,int d){
        i=dd;
        x=d;
    }
    tclass operator++(){

        i++;
        x++;
        return *this;

    }
};

int main() {
    tclass rr(3,3);
    rr++;
    rr++;
    cout<<rr.x<<" "<<rr.i<<endl;
    system("pause");
    return 0;
}
  • 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-27T02:54:20+00:00Added an answer on May 27, 2026 at 2:54 am

    This syntax:

    tclass operator++()
    

    is for prefix ++ (which is actually normally written as tclass &operator++()). To distinguish the postfix increment, you add a not-used int argument:

    tclass operator++(int)
    

    Also, note that the prefix increment better return tclass & because the result may be used after: (++rr).x.

    Again, note that the postfix increment looks like this:

    tclass operator++(int)
    {
        tclass temp = *this;
        ++*this;     // calls prefix operator ++
                     // or alternatively ::operator++(); it ++*this weirds you out!!
        return temp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to deal with friend class for the first time. I wrote
first time trying to deal with this call_user_func_array, but something isn't working, since I
First time trying to deal with users logging in with ASP.net and haven't had
I am trying to figure out the best way to deal with this. First,
I'm trying to do the following without too much special case code to deal
I've been trying to deal with this problem for a couple of hours now
I've got another problem when trying to overload the () operator for array access:
I got this crazy problem I'm trying to deal with. I know that when
I was trying to make virtual operator on C++ class Data { virtual Matrix
Here's the deal. I am trying to build an EditorBuffer class (for text editing

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.