蚌埠住了,高精模板爆error了
最近在写一个高精模板,编译test.cpp,,不知道哪错了,猜测也许是引用绑定的问题?
Error有这个:
10 7 P:\Codes\util\test.cpp [Error] no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'BigInteger')
剩下都是Note。
代码:
big_integer.h
#ifndef UTIL_BIG_INTEGER_H_
#define UTIL_BIG_INTEGER_H_
#include <istream>
#include <ostream>
class BigInteger {
public:
BigInteger();
friend std::ostream& operator << (std::ostream& os, BigInteger&& x);
private:
static const int MAX_LENGTH = 100;
int length;
int signum;
unsigned long long value[MAX_LENGTH];
};
#endif // UTIL_BIG_INTEGER_H_
big_integer.cpp
#include "big_integer.h"
#include <cstring>
#include <istream>
#include <ostream>
BigInteger::BigInteger() {
length = 1;
signum = 1;
std::memset(value, 0, sizeof(value));
}
std::ostream& BigInteger::operator << (std::ostream& os, BigInteger&& x) {
if (x.signum == -1)
os << '-';
for (int i = x.length - 1; i >= 0; i++)
os << x.value[i];
return os;
}
test.cpp
#include "big_integer.h"
#include <iostream>
using namespace std;
BigInteger bi = BigInteger();
int main() {
cout << bi << '\n';
return 0;
}