小编use*_*446的帖子

c ++和重载运算符的新手,不确定如何使用该函数

嗨我是C++的新手,我刚刚学习了一些Java基础知识后开始学习它.我有预先存在的代码,因为它已经超载了>>运算符,但是在看了很多教程并试图理解这个问题之后,我想我会问这里.

Rational cpp文件:

 #include "Rational.h"

#include <iostream>




Rational::Rational (){

}



Rational::Rational (int n, int d) {
    n_ = n;
    d_ = d;
}

/**
 * Creates a rational number equivalent to other
 */
Rational::Rational (const Rational& other) {
    n_ = other.n_;
    d_ = other.d_;
}

/**
 * Makes this equivalent to other
 */
Rational& Rational::operator= (const Rational& other) {
    n_ = other.n_;
    d_ = other.d_;
    return *this;
}

/**
 * Insert r into or extract r from stream …
Run Code Online (Sandbox Code Playgroud)

c++ overloading operators

4
推荐指数
1
解决办法
198
查看次数

标签 统计

c++ ×1

operators ×1

overloading ×1