Overloading the << and >> operators

I'm having problems while trying to overload the << and >> operators.

I have a class called LargeNumber which (in theory :D) which I use to create objects which represent numbers who have more than 20 digits. I have to use a string attribute where the number will be stored, and latter I need to parse its digits(and put them in a list, or stack) so I could do basic arithmetic operations with those numbers (don't ask why :D). But I'm stuck at the very beginning trying to overload these damn operators :D. My code looks like this:

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

#include <iostream>
#include <string>

using namespace std;

class LargeNumber{
      string number;
      friend istream &operator >> (istream &cin, const LargeNumber &a);
      friend ostream &operator << (ostream &out, const LargeNumber &a);
      
      public:
      VelikiBroj();
      string GetNumber() { return number;}
      string SetNumber(string num) { number=num;}
    
};

ostream &operator <<(ostream &cout, const LargeNumber &a){
        cout<<a.number;
        return cout;

}

istream &operator >>(istream &cin, const LargeNumber &a){
        cin>>a.number;
        return cin;
}
   
#endif 



I googled a lot and just couldn't find the solution :// This class is in a header file and here is the compilers log:

In file included from main.cpp:1:
VelikiBroj.h: In function `std::istream& operator>>(std::istream&, const VelikiBroj&)':
VelikiBroj.h:12: error: no match for 'operator>>' in 'cin >> a->VelikiBroj::broj'
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:87: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>&(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:93: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:102: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base&(*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:111: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:133: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:164: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:186: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:217: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:239: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:261: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:284: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:306: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/istream.tcc:329: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]



make.exe: 
*
*
*
[main.o] Error 1

Execution terminated


What is a->VelikiBroj::broj? Just a member of some supported type?

Shouldn't the second parameter for operator>> be non-const (because it's being read in)?
Last edited on
Sorry, I'm from Bosnia and in my language VelikiBroj is LargeNumber :)

And thank you, that was the solution to my problem ^^. Stupid of me to overlook that...
Topic archived. No new replies allowed.