Как сделать передачу параметра в метод по постоянной ссылке? - PullRequest
0 голосов
/ 04 апреля 2019

Мне нужно передать параметр в метод, используя постоянную ссылку.

В строке "bool operator == (const Rational x) const;"Я ставлю «&» перед «x», но это не помогает, что мне делать?

class Rational {
private:
    int chislitel;
    int znum;
public:
    Rational(int chislitel, int znum);
    Rational();
    bool operator==(const Rational x) const;

    void Print();
};

.,.

bool Rational::operator==(const Rational x) const
{
    if (chislitel * x.znum == znum * x.chislitel)
        return true;
    else
        return false;
}

мое решение -> ошибка

1 Ответ

0 голосов
/ 04 апреля 2019

Спасибо @MatthieuBrucher!

 class Rational {
    private:
        int chislitel;
        int znum;
    public:
        Rational(int chislitel, int znum);
        Rational();
        bool operator==(const Rational& x) const;

        void Print();
    };

    bool Rational::operator==(const Rational& x) const
    {
        return chislitel * x.znum == znum * x.chislitel;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...