Hey
i am using an overloaded operator '>>' in one of my cpp files (see code below).
I want to still be able to use "cout" to do screen output, but when i use it, i get the following error:
Code:
no match for `std::ostream& >> const char[43]' operator
i understand that this error is because of the overloaded operator, but how can i get my program to use the standard '>>' so i can use cout? ...
i also tried using cout.operator(" ... "); but that resulted in the error:
Code:
no matching function for call to `std::basic_ostream<char, std::char_traits<char> >::<invalid operator>(const char[43])'
Any help would be appreciated.
cheers
SR.
the call to the overloaded operator:
Code:
void Asteroid::mass_loss( int hours )
{
// need to add 4 and 12 hour code here...
if(hours == 4)
{
}else if(hours == 12)
{
}else
{
cout.operator("incorrect hours entered. Please try again.");
}
}
and the overloaded operator:
Code:
ostream& operator << ( ostream& os, const Asteroid& a )
{
os << dynamic_cast<const ImpactBody&>(a)
<< endl
<< "debris index: " << a.debrisIndex ;
return os;
}
istream& operator >> ( istream& is, Asteroid& a )
{
is >> dynamic_cast<ImpactBody&>( a );
cout << "Enter debris index >> ";
getline( is, a.debrisIndex );
return is;
}
ofstream& operator << ( ofstream& os, const Asteroid& a )
{
os << 'A' << endl
<< static_cast<const ImpactBody&>(a)
<< a.debrisIndex << endl;
return os;
}
ifstream& operator >> ( ifstream& is, Asteroid& a )
{
is >> dynamic_cast<ImpactBody&>( a );
getline( is, a.debrisIndex );
return is;
}