return_type operatoroperator_symbol( parameters )
{
statements
}
| Example: | int operator-( Time a, Time b )
{
return a.seconds_from( b )
} there are two types of operator overloading,one is operator function,another is operator member function. as an operator function,if unary, time operator--(time& a); if binary, int operator-(time a,time b); as an operator member function, if unary,then Fraction& operator++(); // Prefix form
Fraction operator++(int unused); // Postfix form if binary,then
Fraction& operator+=(const Fraction& right);
有很多advanced topics
|
没有评论:
发表评论