我需要制作一个程序,从用户那里获取一小部分,然后对其进行简化。
我知道如何做到这一点,并且已经完成了大部分代码,但我不断收到此错误“错误:‘.’令牌之前预期有不合格的 id”。
我已经声明了一个名为“ReducedForm”的结构,它包含简化的分子和分母,现在我想做的是将简化的值发送到该结构。
这是我的代码;
在 Rational.h 中;
#ifndef RATIONAL_H
#define RATIONAL_H
using namespace std;
struct ReducedForm
{
int iSimplifiedNumerator;
int iSimplifiedDenominator;
};
//I have a class here for the other stuff in the program
#endif
在 Rational.cpp 中;
#include <iostream>
#include "rational.h"
using namespace std;
void Rational :: SetToReducedForm(int iNumerator, int iDenominator)
{
int iGreatCommDivisor = 0;
iGreatCommDivisor = GCD(iNumerator, iDenominator);
//The next 2 lines is where i get the error
ReducedForm.iSimplifiedNumerator = iNumerator/iGreatCommDivisor;
ReducedForm.iSimplifiedDenominator = iDenominator/iGreatCommDivisor;
};
您正在尝试使用静态访问该结构.
代替::
,其成员也不是static
。要么实例化ReducedForm
:
ReducedForm rf;
rf.iSimplifiedNumerator = 5;
或将成员更改为static
像这样:
struct ReducedForm
{
static int iSimplifiedNumerator;
static int iSimplifiedDenominator;
};
在后一种情况下,您必须使用以下方式访问成员::
代替.
然而,我非常怀疑后者就是你想要的;)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)