嗨我是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)