我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

c++后置递增运算符重载


#include
using namespace std;
class person {
    friend ostream& operator<<(ostream& cout, person& p);
public:
    person()
    {
        a = 0;

    }
public:
    person& operator++()
    {
        ++a;
        return *this;
    }
    person operator++(int)
    {
        person temp = *this;
        a++;
        return temp;
    }

private:
    int a;
};
ostream& operator<<(ostream& cout, person& p)
{
    cout << p.a;
    return cout;
}
int main()
{
    person p;
    cout << ++p<return 0;
}

main函数中下面的<<报错

img

C++:递增运算符重载_咩咩要学习的博客-CSDN博客_c++递增运算符重载 作用:通过重载递增运算符,实现自己的整型数据后置++://重载递增运算符//自定义整形class MyInt{ friend ostream& operator<<(ostream& cout, MyInt myint); public: MyInt() { m_Num = 0; } //重载后置++运算符 //int代表占位参数,可以用于区分前置和后置 MyInt operator+ https://blog.csdn.net/weixin_45663220/article/details/113610605?ops_request_misc=&request_id=&biz_id=102&utm_term=c++%E5%90%8E%E7%BD%AE%E9%80%92%E5%A2%9E%E8%BF%90%E7%AE%97%E7%AC%A6%E9%87%8D%E8%BD%BD&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-113610605.142^v63^js_top,201^v3^control_1,213^v1^control&spm=1018.2226.3001.4449

近期文章

  • 自学python没有思路求指导
  • Alfredo's Pizza Restaurant
  • 关于#C++#的问题,头文件stdio.h错误
  • Character set 'utf8mb3' is not supported by .Net Framework.
  • Android Studio的模拟器闪屏
  • 怎么试了好多遍还是错的!【抓狂】【抓狂】
  • prometheus redis exporter安装详解
  • 这个程序为什么没跑起来呢
  • 对于统计字母,数字,空格,和其他字符个数的问题
  • 关于python post问题,
  • 求解答,这是为什么,链表问题有点难
  • 键盘的程序怎么编写,Broken Keyboard
  • 虚拟机linux安装sqlite arm-linux-ranlib: command not found
  • 试了好多遍怎么又是错的!【抓狂】【抓狂】
  • 这里用List接口找不到Listof的方法,如何解决?
  • c语言,统计字符类型个数
  • 关于#c语言#的问题:编写函数名为fun的来查找1000以内这20个数并求和,运行主函数后最终输出这20个数及它们的和
  • 请问这种是什么意思?
  • while 里的scanf如何理解
  • 根据用户选择实现日期天数互转的代码问题

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华