There is a stack overflow, and I don't know why

-4

Whenever I try to run this code, it stops and states, Unhandled exception at 0x00E227D9 in ProjectName.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00E42F74). occurred.

This is the code and it and the exception is in the file Fraction.cpp at the constructor.

Fraction.cpp

#include "Fraction.h"

// Constructor
Fraction::Fraction(int numerator, int denominator) 
{ // This is where the exception gets thrown
    setNumerator(numerator);
    setDenominator(denominator);
}

std::istream& operator>> (std::istream& in, const Fraction& fraction)
{
    in >> fraction.m_numerator;
    in.ignore(std::numeric_limits<std::streamsize>::max(), '/');
    in >> fraction.m_denominator;

    return in;
}

std::ostream& operator<< (std::ostream& out, const Fraction& fraction)
{
    out << fraction.getNumerator() << '/' << fraction.getDenominator();

    return out;
}

c++
stack-overflow
asked on Stack Overflow May 18, 2020 by Sahibjot Singh • edited May 18, 2020 by yagizcandegirmenci

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0