Reputation: 46
I have a strange error (no match for 'operator<<' in std::cout << BigReal::operator-()() ) when doing this:
cout<<(-D);
where << is overloaded as following:
ostream & operator<<( ostream &c, BigReal &n )
{
c << n.nume << "=" << "[" << n.nr << "] ";
return c;
}
and unary - as:
BigReal BigReal::operator-( void )
{
float negativ = atof( nr );
char buff[ 1000 ];
sprintf( buff, "%f", -negativ );
//strcpy( nr, buff );
BigReal Rez(buff, "Nr.");
return Rez;
}
and D is a BigReal.
Upvotes: 0
Views: 121
Reputation: 311088
Expression -D creates a temporary object. A temporary object may be bound to const reference. So change operator << the following way
ostream & operator<<( ostream &c, const BigReal &n );
Upvotes: 2