When I try to assign value to my map, it gives me this error. What's wrong with my constructor? This only happens when I declared the key as BigInt. It works if the key is int, or string.
C2678 binary '<': no operator found which takes a left-hand operand of type 'const _Ty' (or there is no acceptable conversion)
#include <iostream>
#include <vector>
#include <map>
using namespace std;
class BigInt {
private:
vector<char> v;
public:
BigInt();
BigInt(string s);
BigInt(int);
BigInt(const BigInt& b);
void print();
};
int main()
{
cout<<"Hello World";
BigInt b("12345");
b.print();
static map<BigInt,BigInt> m;
m[b] = b;
return 0;
}
BigInt::BigInt() {
}
BigInt::BigInt(string s) {
string:: reverse_iterator rit;
for(rit = s.rbegin(); rit != s.rend(); rit++){
v.push_back((int)*rit - '0');
}
}
BigInt::BigInt(int n) {
while (n > 9) {
int digit = n % 10;
v.push_back(digit);
n = n/10;
}
v.push_back(n);
}
BigInt::BigInt(const BigInt& b) {
copy(b.v.begin(), b.v.end(), back_inserter(v));
}
void BigInt:: print() {
vector<char>::reverse_iterator rit;
for (rit = v.rbegin(); rit != v.rend(); rit++) {
cout << (int)*rit;
}
}