I was compiling an old programming assignment about manipulating polynomials represented as linked list of its terms and I ran into a plethora of unfamiliar errors. I originally used Visual Studio Express to do the assignment, where it successfully compiled and ran, if I remember correctly. Recently, however, I installed Ubuntu on an old Thinkpad and decided to give gcc/g++ a test run. Unfortunately, it failed to compile and gave me some strange errors on two lines where I declare a method a friend of the Term class. Here are the errors and relevant part of Poly.h.
In file included from assign7.cpp:9:
Poly.h:20: error: expected ‘,’ or ‘...’ before ‘&’ token
Poly.h:20: error: ISO C++ forbids declaration of ‘Poly’ with no type
Poly.h:21: error: expected ‘,’ or ‘...’ before ‘&’ token
Poly.h:21: error: ISO C++ forbids declaration of ‘Poly’ with no type
Code:/* [Removed personal info] */ #include <iostream> #include <string> #include <sstream> #include <math.h> using namespace std; /* A class representing a term of a polynomial as a node in a linked list. Contains value of coefficient, degree, and a pointer to the next list */ class Term { friend class Poly; friend ostream& operator<<(ostream& out, const Poly& p); //Line 20 friend istream& operator>>(istream& in, const Poly& p); //Line 21 public: Term(float c, int d) { coefficient = c; degree = d; next_term = 0; } Term() { coefficient = 0; degree = 0; next_term = 0; } const float evaluate(float x) const { return ( coefficient * pow(x,degree) ); } const Term operator+(const Term& b) const; const Term operator*(const Term& b) const; const bool operator==(const Term& b) const; const bool operator!=(const Term& b) const; private: float coefficient; int degree; Term *next_term; };



LinkBack URL
About LinkBacks


