我知道我可以在postfix operator ++中使用哑元int someClassObject.operator++(5),但是为什么不能像这样使用它someClassObject++5呢?我问这是因为operator+可以这样使用someClassObject1 + someClassObject2。
{
public:
test(int x, string y) : x(x), y(y){}
test() :x(0), y("") {};
//skiping some code for copy constructor and assignment operator overload
test operator++(int x)
{
test a(*this);
a.x += x;
++(*this);
return a;
}
friend ostream& operator<<(ostream& ost, const test& test)
{
ost << test.x << " , " << test.y;
return ost;
}
int x;
string y;
};
int main()
{
test t1(5, "testing"); …Run Code Online (Sandbox Code Playgroud)