I do not understand why my compiler is saying:
type specifier omitted for parameter
FULL COMPILE ERRORS:
Terms.cpp:12: type specifier omitted for parameter
Terms.cpp:12: parse error before `&'
Terms.cpp:13: `operator >>(...)' must have an argument of class or enumerated type
Terms.cpp:13: `operator >>(...)' must take exactly two arguments
Terms.cpp: In function `class istream & operator >>(...)':
Terms.cpp:32: `istr' undeclared (first use this function)
Terms.cpp:32: (Each undeclared identifier is reported only once
Terms.cpp:32: for each function it appears in.)
Terms.cpp:41: `data' undeclared (first use this function)
Terms.cpp:62: `ture' undeclared (first use this function)
I tried adding:
istream:: istream& operator >> (istream& istr, Term& data)
but that did not work aswell
My .h file includes:
and my .cpp includesCode:#ifndef TERMS_H #define TERMS_H #include <iostream> class Terms { public: Terms() {}; // Default constructor void SetCoefficient (int a) { coef = a; }; // Sets coef // Pre: An object Term has been declared // Post: coef is set to the number passed in void SetExponent (int a) { exp = a; }; // Sets exp // Pre: An object Term has been declared // Post: coef is set to the number passed in void SetTermPrint (bool a) { okToPrint = a; }; // If the string being proccess contains ONLY a + or a - // This will be set to false since we do not want to store // these items in the linked list with an array of records // Pre: An object Term has been declared // Post: If the term is only a + or a - okToPrint is false // else true. void SetIfAnX (bool a) { hasAnX = a; }; // If the term being proccessed contains an X we set a to true // Else false. This is neccessary since when we eventually find // the polynomials derivative if no exists exist we want to ignore // this term since it becomes 0. // Pre: An object Term has been declared // Post: If the string being passed in contains an x this sets hasAnX to be true // else false; int GetCoefficient () { return coef; }; // Returns what is stored in coef // Post: coef is returned int GetExponent () { return exp; }; // Returns what is stored in exp // Post: exp is returned bool GetTermPrint() { return okToPrint; }; // Returns what is stored in okToPrint; // Post: okToPrint is reutrned bool GetIfAnX () { return hasAnX; }; // Returns what is stored in hasAnX // Post: hasAnX is returned private: int coef; int exp; bool okToPrint; bool hasAnX; // friend istream& operator >> ( istream&, Terms& ); }; istream& operator >> (istream& istr, Terms& data); #endif
Thanks,Code:// Terms.cpp // This class is used to overload the input operator and set an object Term to have: // 1) its coefficient // 2) its exponent // 3) if it contains an x // 4) if it is needed to print #include <stdlib.h> #include <string> #include "Terms.h" istream& operator >> (istream& istr, Term& data) { int number; int exponent; bool print; bool isThere; bool isNegative; string line; string tempNum; string tempExp; const char* num; const char* exp; int length; isNegative = false; print = true; isThere = false; tempNum = ""; tempExp = ""; istr >> line; cout << "THE LINE: " << line << endl; if ( !istr.fail() ) { if (line == "-") { isNegative = true; print = false; data.SetPrint(print); } else if (line == "+") { print = false; data.SetPrint(print); } else { line = line + ";"; length = line.size(); for (int i = 0; i < length; i++) { if( isdigit(line[i]) ) { tempNum = tempNum + line[i]; } else if ( line[i] == 'x' ) { isThere = ture; i++; if ( line[i] == ';' ) tempExp = tempExp + "1"; i--; if (tempNum == "" || tempNum == "-") tempNum = tempNum + "1"; } else if( line[i] == '^' ) { i++; while ( line[i] != ';') { tempExp = tempExp + line[i]; i++; } } else if ( line[i] = '-' ) { tempNum = tempNum + line[i]; } } if ( tempExp == "" ) tempExp = "1"; num = tempNum.c_str(); exp = tempExp.c_str(); number = atoi(num); exponent = atoi(exp); if (isNegative) { number *= -1; isNegative = false; } } } data.SetPrint(print); data.SetIfAnX(isThere); data.SetNumber(number); data.SetCoefficient(exponent); return istr; }
Chris



LinkBack URL
About LinkBacks


