吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1372|回复: 9
收起左侧

[C&C++ 转载] c++operator++运算符重载。

[复制链接]
zds212 发表于 2021-5-4 22:15
本帖最后由 zds212 于 2021-5-7 22:33 编辑

[C++] 纯文本查看 复制代码
#include<iostream>
using namespace std;

class mint
{
        friend ostream& operator<<(ostream& cout, mint p);
public:
        mint()
        {
                number = 0;
        }
        mint& operator++()
        {
                number++;
                return *this;
        }
        mint operator++(int)
        {
                mint temp=*this;
                number++;
                return temp;
        }

private:
        int number;
};

ostream& operator<<(ostream& cout,mint p)
{
        cout << p.number;
        return cout;
}

void text01()
{
        mint p;
        cout << ++(++(++p)) << endl;
        cout << p++<<endl;
        cout << p << endl;
}

int main()
{
        text01();
        system("pause");
        return 0;
}

免费评分

参与人数 2吾爱币 +2 热心值 +2 收起 理由
zds1234 + 1 + 1 用心讨论,共获提升!
lichen218 + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| zds212 发表于 2021-5-5 09:05

是输出的意思。
gms 发表于 2021-5-5 00:33
列明 发表于 2021-5-5 00:30
<<是什麽意思呢?
今天見了兩三次了,
看不懂。
是移位麽?
angel8327 发表于 2021-5-5 11:51
运算符重载那时候看了好多遍视频,现在又忘了...
列明 发表于 2021-5-6 00:23
gms 发表于 2021-5-5 00:33
左移运算符,在C++中就是输出功能

謝謝解惑!
但是這兩段還是不明白。
ostream& operator<<(ostream& cout,mint p)
{
        cout << p.number;
        return cout;
}

void text01()
{
        mint p;
        cout << ++(++(++p)) << endl;
        cout << p++<<endl;
        cout << p << endl;
}
列明 发表于 2021-5-6 00:27
zds212 发表于 2021-5-5 09:05
是输出的意思。

嗯,
感謝。
 楼主| zds212 发表于 2021-5-6 09:14
列明 发表于 2021-5-6 00:23
謝謝解惑!
但是這兩段還是不明白。
ostream& operator

void text01()
{
        mint p;
        cout << ++(++(++p)) << endl;
        cout << p++<<endl;
        cout << p << endl;
}
这个的++ 是计算用的,一次也可以,我用了三次。        cout << ++(++(++p)) << endl;
gms 发表于 2021-5-6 13:13
列明 发表于 2021-5-6 00:23
謝謝解惑!
但是這兩段還是不明白。
ostream& operator

重载了加号运算符,对自定义的数据类型(mint这个类)相加
头像被屏蔽
伊芙加登 发表于 2021-5-6 20:24
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-30 10:45

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表