1) whats wrong with the static members they give error "the function should be non static or non member function
2) while defining the functions how do I differentiate between the definition
#include<iostream>
#include<fstream>
#include<sstream>
usingnamespace std;
//-----------------------------------------------------
//class of Term that has two variables of type T
template<class T>
class Term
{
private:
T coeffi;
T exp;
public:
//setters and getters
void setCoeffi(T);
void setExp(T);
T getCoeffi();
T getExp();
//constructors and distructors
Term();//term with coeffi and exp 1
//Term(int);//term with coeffi
//Term(int, int);
};
template<class T>
Term<T>::Term()
{
coeffi =1;
exp =1;
}
//--------------------------------------------------------
//class of polynomial that will contain a variable of term
template<class T>
class Polynomial
{
private:
Term<T>* arrOfTerm;
public:
Polynomial();//will intialize a polynomial form coeffi 1 and exp1
Polynomial(const Polynomial& obj);//copy constructor
Polynomial(T coeffi[],int order);//coeffi are in array and order given
Polynomial(Term<T> a[],int size);//the poly will be init by an array of
//term which contains coeffi and exp and size is the size of array of term
Polynomial(string);//a poly will be given in string form
~Polynomial();
void setArrOfTerm();
void setXthTerm(int x);
Term<T> getXthterm(int x);
//operators =, +, -, *, ==, !=, <<, >>, []
Polynomial operator =(const Polynomial& obj);
static Polynomial<T> operator =(const Polynomial<T>& obj);
Polynomial operator +(const Polynomial& obj);
static Polynomial operator +(const Polynomial& obj);
Polynomial operator -(const Polynomial& obj);
Polynomial operator *(const Polynomial& obj);
booloperator ==(const Polynomial& obj);
booloperator !=(const Polynomial& obj);
friend istream& operator >><T>(istream& in,Polynomial<T>& obj);
friend ostream& operator <<<T>(ostream& out,Polynomial<T>& obj);
voidoperator [](int index);
};
Develop a class Polynomial containing at least:
a. constructors and destructor
b. set and get functions
c. toString function
d. evaluate function
e. The class should also provide the following overloaded operator
=, +, -. *, ==, !=, <<, >>and []
1. Also provide, both non-static and static members, methods for all operators of part e.
The assignment (=) operator is incorrectly declared as static. Assignment operators cannot be static. For more information, see User-Defined Operators.
That applies to [] and () as well.
C++ simply forbids that.
The static version of + nonetheless would be static Polynomial operator +(const Polynomial& obj1, const Polynomial& obj2);
1. Also provide, both non-static and static members, methods for all operators of part e.
I think that means you have to create functions that do the same thing the operators do, like an add function for the operator +, equal for operator ==, etc.