C++ 之运算符重载
发布日期:2021-05-14 16:35:29 浏览次数:14 分类:精选文章

本文共 3890 字,大约阅读时间需要 12 分钟。

C++���������������������

���������������������������

������������������C++������������������������������������������������������������������������������������������������������������������������������������������������������ tblabez���������������������������C++������������������������������������������������������������������������������������������������������������������������

  • + ���������������������������������������������������������������������������
  • < ������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������

���������������������������������������������������������������������������������������������������������������

������������������������������������

���C++���������������������������������������������������

  • ���������������������������������������������������������������������������������������������������������

  • ������������������������������������������������������������������������������������������������������������+ ������������������������������������������������������

  • ��������������������������������������������� a + b��������������������� a.operator+(b)���������������������������������������������������������������������������������

  • ���������������������������������������������������������������������

    • ������������������������������ ., *, ::, sizeof, ��� ?: werent't���������������
    • ������������������������������������������������������������������������������������== ���������������������������������
    • ������������������������������������������������������������������������������������������* ��������������������������� +���������������������������������������
    • ������������������������������������������������������������������������������������������������������������������������������������

    ������������������������������������

    ��������������������������������������������������������������������������������������������� Integer ���������

    class Integer {public:    Integer(int value) : m_value(value) {}    const Integer operator+(const Integer other) const;    const Integer operator-(const Integer other) const;    const Integer operator*(const Integer other) const;    const Integer operator/(const Integer other) const;    const Integer operator%(const Integer other) const;    const Integer& operator=(const Integer& other);    ~Integer();    int intValue() const { return m_value; }private:    int m_value;};

    ���������

    • operator+ ��������������� Integer ������������������������
    • operator= ���������������������������������������������������������������������������

    ������������������������������������������

    ��������������������� Integer ������ num1 ��� num2���������������������������������������������

    Integer num3 = num1 + num2; // ������ num1.operator+(num2)

    ��������������������������� +���������������������������������������������������������

    ���������������������������������������������

    ������������������������������������������������������

  • ������������������������������������������������������������������������������������������������������������������

  • ������������������������������������������������������������������������������������������������ x = x + y ������������������������������������������������������������

  • ��������������������������������������� static_cast ������ const/ilnk ������������������������������

  • ������������

    ������������������C++������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ API���

    ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:C++ 之const详解
    下一篇:线性代数 笔记1

    发表评论

    最新留言

    很好
    [***.229.124.182]2025年04月19日 16时05分25秒