Keroro540
Keroro540

Reputation: 1

How do you call a private class function (with parameters), in a public function of the same class?

So, I'm writing up a program that is focusing on operator overloading.

I'm trying to write up a private function to find the least common denominator of two rational numbers (objects in main). Right now, the accessor just doesn't like the parameters of the private lcd function.

here's my lcd private function:

long CRational::lcd(const CRational &rationalNumber) const{
    long gCF = 0;
    long lCD = 0;
    if (m_denominator != 0 && rationalNumber.m_denominator != 0){
        gCF = gcf(m_denominator, rationalNumber.m_denominator);
        lCD = ((m_denominator / gCF)*rationalNumber.m_denominator);
    }

    return lCD;
}

Here's what I attempted for the accessor:

long CRational::getLCD() const
{

    return lcd(const CRational &rationalNumber);
}

Right now, I'm getting red squigglies under the const and &rationalNumber. const - name type not allowed &rationalNumber - unidentified

Was hoping someone could help me out before I go insane?

Upvotes: 0

Views: 122

Answers (1)

coyotte508
coyotte508

Reputation: 9705

Try this:

long CRational::getLCD(const Rational &rationalNumber) const
{
    return lcd(rationalNumber);
}

Upvotes: 1

Related Questions