c ++指针:重载运算符++

0 c++ operator-overloading

我尝试找到有关重载operator ++ for pointer的任何内容,但没有结果.

有我的代码.

struct Item
{
    int amount;
    Item(int a){ this->amount = a; };
    Item& operator++()
    { 
       this->amount++; 
       return *this;
    };
};


int main()
{

    Item *I = new Item(5);

    ++*I;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

是否有任何选项只能在main函数中编写

++I;
Run Code Online (Sandbox Code Playgroud)

(抱歉我的英文)

0x4*_*2D2 6

只是不要使用指针(无论如何都不需要它):

Item I(5);
++I;
Run Code Online (Sandbox Code Playgroud)

  • 你的意思是'项目I(5)` (3认同)