Compiler: MSVC
So I am trying to implement my own number system that can store infinite numbers in C++. What I did was overload operator<<
for my custom class BigInt
as such:
inline std::ostream& operator<<(std::ostream& os, BigInt& bint)
{
os << bint.num; // num is a std::string
return os;
}
Now I implemented addition for my custom numbers:
inline BigInt& operator+(BigInt& bint1, BigInt& bint2)
{
BigInt sum;
// addition code...
return sum;
}
Now when I try to print a BigInt
like this:
BigInt bint1("123");
std::cout << bint1;
..it works. But nothing prints out when I do this:
BigInt bint1("123"), bint2("456");
std::cout << bint1 + bint2;
I suspect some sort of UB here. What am I doing wrong here?