1 First of all you need to replace the includes of RationalFraction.h
and IrrationalFraction.h
with forward class declarations, like this:
class RationalFraction;
class IrrationalFraction;
2 Second, you need to add those includes in file Fraction.cpp
.
3 Third, you need to add includes of Fraction.h
in RationalFraction.h
and IrrationalFraction.h
.
4 Fourth, you need to add implementations of getType
in both those classes.
5 Fifth, to avoid serious problems with name collisions and such, you need to remove using namespace std;
from the headers.
6 Sixth, to avoid double deletions, which is Undefined Behavior, you have to either disallow copying, or handle copying. One way to handle copying is to use smart pointers instead of raw pointers. Another is to define copy constructor and copy assignment operator (that's a bit over-simplified, but you can easily find the details: google for "rule of three").
7 The constructor of Fraction
unconditionally calls the constructor of IrrationalFraction
, which calls the constructor of Fraction
. This is an infinite recursion which must be resolved some way. You'll find that when you start testing.
The design here looks very Java-esque.
Have you considered class templates?