static and non static member problem

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 #include<iostream>
#include<fstream>
#include<sstream>
using namespace 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);
        bool operator ==(const Polynomial& obj);
        bool operator !=(const Polynomial& obj);
        friend istream& operator >><T>(istream& in,Polynomial<T>& obj);
        friend ostream& operator <<<T>(ostream& out,Polynomial<T>& obj);
        void operator [](int index);
};
The operators shouldn't be static. static operators doesn't really make sense because you are going to use them on objects.
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.
anyone??
it's raccomanded to NOT USE both static and template in class definition.
msdn wrote:
'type' : static 'operator =' function is illegal

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.
thanks guys Vins3Xtreme,coder777 and bbgst and peter87 thanks
Topic archived. No new replies allowed.