我有一个简单的程序。主要由我的教授提供。我们要编写 3 个函数,称为enter
, simplify
, display
。
主要的
#include <iostream>
using namespace std;
// #include "fraction.h"
struct Fraction {
int numerator;
int denominator;
};
void enter(struct Fraction* fraction);
void simplify(struct Fraction* fraction);
void display(struct Fraction fraction);
int main()
{
struct Fraction fraction;
cout << "Fraction Simplifier" << endl;
cout << "===================" << endl;
enter(&fraction);
//simplify(&fraction);
//display(fraction);
}
void enter(struct Fraction* fraction) {
cout << "Numerator: " << endl;
cin >> *fraction.numerator; // the line that doesn't work, line 31
}
void simplify(struct Fraction* fraction) {}
void display(struct Fraction fraction) {}
错误:
w2.cpp:31:19: error: request for member ânumeratorâ in âfractionâ, which is of non-class type âFraction*â
有问题的线路
void enter(struct Fraction* fraction) {
cout << "Numerator: " << endl;
cin >> *fraction.numerator; // the line that doesn't work, line 31
}