// inherit5.cpp By: Aiman Hanna - ©1993-2002 Aiman Hanna // This program illustrates the need of having a default constructor. // As you have some constructors for Geometric, the system will not generate // any default constructors for you. Now, if non of your constructors // is a default one, the system may create a compilation error whenever // a need for this default constructor is encountered, or in other cases, // the program may behave unexpectedly. // Key Points: 1) Default Constructors. #include "inherit5.h" // Define the base class Geometric::Geometric( int lf , int tp, int bt, int rt ) { cout << " Gm...Executing the 'parameterized' constructor of the base class. " << "\n"; left = lf; top = tp; bottom = bt; right = rt; cout << " Gm...Left is: " << left << " , top: is " << top << " , bottom is: " << bottom << " and right is: " << right << "\n"; } void Geometric::Draw( void ) { cout << " Gm...Function Draw in the base class is executing." << "\n"; cout << " Gm...This function will execute for all the derived classes!" << " unless it is redefined!! " << "\n"; } void Geometric::Erase( void ) { cout << " Gm...Function Erase in the base class is executing." << "\n"; cout << " Gm...This function will execute for all the derived classes!" << " unless it is redefined!! " << "\n"; } void Geometric::Move( void ) { cout << " Gm...Function Erase in the base class is executing." << "\n"; cout << " Gm...This function will execute for all the derived classes!" << " unless it is redefined!! " << "\n"; } // define the TwoDimension class TwoDimension::TwoDimension( void ) { // This is line 68 cout << " TD...Executing the default constructor of the TwoDimension class. " << "\n"; fillpattern = 0; } TwoDimension::TwoDimension( int lf, int tp, int bt, int rt, int fill ): Geometric( lf, tp, bt, rt ) { cout << " TD...Executing the 'parameterized' constructor of the" << " TwoDimension class. " << "\n"; fillpattern = fill; cout << " TD...Left is: " << left << " , top: is " << top << " , bottom is: " << bottom << " and right is: " << right << "\n"; } void TwoDimension::Draw( void ) { cout << " TD...Function Draw in the TwoDimension class is executing." << "\n"; cout << " TD...This function redefines the function Draw in the base class" << "\n"; } // define the Rectangle class Rectangle::Rectangle( void ) { cout << " Rec...Executing the default constructor of the Rectangle class. " << "\n"; boardershape = bolddashed; } Rectangle::Rectangle( int lf , int tp, int bt, int rt, int fill ): TwoDimension( lf, tp, bt, rt, fill ) { cout << " Rec...Executing the 'parameterized' constructor of the" << " Rectangle class. " << "\n"; boardershape = bolddashed; cout << " Rec...Left is: " << left << " , top: is " << top << " , bottom is: " << bottom << " and right is: " << right << "\n"; } void Rectangle::SetBoarderShape( boarder brd ) { boardershape = brd; } int main( void ) { Geometric Gm( 2, 5, 8, 10 ); cout << " Gm...Now the draw function of the Geometric class will start. " << "\n"; Gm.Draw( ); cout << "*************************************************\n\n"; TwoDimension TD( 4, 7, 9, 12, 1 ); cout << " TD...Now the draw function of the TwoDimension class will start. " << "\n"; TD.Draw( ); TD.Erase( ); cout << "*************************************************\n\n"; Rectangle Rec( 5, 11, 16, 20, 2 ); cout << " Rec...Now the draw function of the Rectangle class will start. " << "\n"; Rec.Draw( ); Rec.Move( ); cout << "*************************************************\n\n"; return 0; } /// The result of compiling the progarm: // On VC++ // inherit5.cpp(68) : error C2512: 'Geometric' : no appropriate default constructor available // Error executing cl.exe. // On UNIX // CC: "inherit5.cpp", line 68: error: argument 1 of type int expected for Geometric::Geometric() (1266)