https://www.zhihu.com/question/23511471
和上面的问题差不多。
http://www.cnblogs.com/xkfz007/articles/2506022.html
但是还是不算太清楚,所以打算自己测试下,
平台x86_64,win7,在vs2012上测,没有开优化选项/Od
1.
int main(int argc, char **argv) {
Rational x(1, 5), y(2, 9);
Rational z = x * y;
cout << "calc result: " << z.numerator() << "/" << z.denominator() << endl;
return 0;
}
#include <iostream>
using namespace std;
class Rational
{
friend Rational operator*(const Rational& lhs, const Rational& rhs);
public:
Rational(int numerator = 0, int denominator = 1) : n(numerator), d(denominator) {
cout << "Constructor Called..." << endl;
}
~Rational() {
cout << "Destructor Called..." << endl;
}
Rational(const Rational& rhs) {
this-&g