I need to make a program that gets a fraction from the user and then simplifies it.I know how to do it and have done most of the code but I keep getting this error "error: expected unqualified-id before ‘.’ token".I have declared a struct called ReducedForm which holds the simplified numerator and denominator, now what Im trying to do is send the simplified values to this struct.Here is my code;In Rational.h;#ifndef RATIONAL_H#define RATIONAL_Husing namespace std;struct ReducedForm{ int iSimplifiedNumerator; int iSimplifiedDenominator;};//I have a class here for the other stuff in the program#endifIn 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 errorReducedForm.iSimplifiedNumerator = iNumerator/iGreatCommDivisor;ReducedForm.iSimplifiedDenominator = iDenominator/iGreatCommDivisor;}; 解决方案 You are trying to access the struct statically with a . instead of ::, nor are its members static. Either instantiate ReducedForm:ReducedForm rf;rf.iSimplifiedNumerator = 5;or change the members to static like this:struct ReducedForm{ static int iSimplifiedNumerator; static int iSimplifiedDenominator;};In the latter case, you must access the members with :: instead of . I highly doubt however that the latter is what you are going for ;) 这篇关于错误:“."标记之前的预期未限定ID//(结构)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 06:15