Trouble with operator overloading

Hi,

I'm getting following error message


g++ -c testBigNum.cpp -o testBigNum.o
testBigNum.cpp: In function ‘int main()’:
testBigNum.cpp:14: error: no match for ‘operator=’ in ‘c = a.bigNum::operator+(((bigNum&)(& b)))’
BigNum.h:24: note: candidates are: bigNum& bigNum::operator=(bigNum&)



Could any please help me to figure out what is happening. I got this error after writing code for overloading
+
. Overloading of
=
was working before i wrote code for overloading
+
. So, I guess that my function definition is wrong for operator
+


Thanks.

--------------------------
Pasted below is my code.


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
#ifndef _BigNum_H_
#define _BigNum_H_

#define MAXDIGITS 100

#define PLUS 1
#define MINUS -1

#include <iostream>
#include <string>
using namespace std;


class bigNum
{
        public:
                bigNum();
                bigNum(long);
                friend ostream & operator<<(ostream &, bigNum);
                friend istream & operator>>(istream &, bigNum &);
                bigNum operator+(bigNum &);
//              bigNum & operator-(bigNum &);
                bool operator==(bigNum &);
                bigNum & operator=(bigNum &);
        private:
                char digits[MAXDIGITS];
                int signbit;
                int lastdigit;
                int getSignBit() const;
                char getDigit(int) const;
                int getLastDigit() const;
                void setLastDigit(int);
                void setDigit(int, int);
                void setSignBit(int);
};
#endif


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include "BigNum.h"

using namespace std;

int main()
{
        bigNum a,b,c;
        try
        {
                cin >> a;
                cin >> b;

                c = a+b;
                cout << "This is a "<< a << endl;
                cout << "This is b "<< b << endl;
                cout << "This is c "<< c << endl;
        }
        catch(int n) { cerr << "Exception overflow. Size of number " << n+1 << endl; abort();}
        catch(char a) { cerr << "Entered invalid  character  as number" << endl; abort();}
        return 0;
}


You've defined bigNum & operator=(bigNum &);, but the compiler expects the assignment to bebigNum & operator=(const bigNum &);. You should consider making the input parameters to the other operators const as well.
Thanks.. it worked.. i think I need to read the book again thoroughly..
Topic archived. No new replies allowed.