尝试在 Visual Studio 2010 中编译下面的代码给了我两个关于未解析外部符号的错误。我很确定问题是因为我在一个函数中使用了一个函数,但我不知道具体我做错了什么。代码对我来说看起来不错。
#include <iostream>
using namespace std;
class fraction
{
public:
int gcd(int, int);
void simplifyfraction();
private:
int integral, numerator, denominator;
};
int main(){
return 0;
}
int gcd(int numerator, int denominator)
{
if (denominator > numerator)
return gcd(denominator, numerator);
if (numerator == denominator)
return numerator;
if (numerator%denominator == 0)
return denominator;
return gcd(numerator, numerator-denominator);
}
void fraction::simplifyfraction()
{
int mygcd;
mygcd = gcd(numerator, denominator);
numerator = numerator/mygcd;
denominator = denominator/mygcd;
}