class Rational{ public: const Rational operator*( const Rational& rhs); Rational(int num); private: int a; }; Rational::Rational(int num) :a(num) { } const Rational Rational::operator*(const Rational& rhs) { return Rational(this->a * rhs.a); } int main() { Rational a(2); Rational b(3); Rational c = a * b; return 0; }
时间: 2024-12-29 05:41:29