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:usersahmeddesktopcppqcppqcppq.cpp 25
Warning 2 warning C4620: no postfix form of 'operator ++' found for type 'tclass', using prefix form c:usersahmeddesktopcppqcppqcppq.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;
}
See Question&Answers more detail:os