hello everyone, this deals with using default values insteed of Overloading a function... but anyways...here is the code:
Code://Default.h enum BOOL{TRUE,FALSE}; class Rectangle { public: //constructors Rectangle(int Height, int Width); ~Rectangle(); void DrawShape(int aHeight, int aWidth, BOOL CurrentDefault = FALSE) const; private: int itsHeight; int itsWidth; }; //implamation Rectangle::Rectangle(int Height, int Width) { itsHeight = Height; itsWidth = Width; } Rectangle::~Rectangle() { //desctor } void Rectangle::DrawShape(int aHeight,int aWidth, BOOL CurrentDefault ) const { int PrintHeight; int PrintWidth; if(CurrentDefault == TRUE) { PrintHeight = aHeight; PrintWidth = aWidth; }else{ PrintHeight = Height; //errors found here PrintWidth = Width; //and here! } for(int i = 0; i < PrintHeight; i++) { for(int j = 0; j < PrintWidth; j++) { cout <<"*"; } cout <<"\n"; } }
here is the Default.cpp:
Code:#include <iostream.h> #include "Default.h" void main() { Rectangle theRect(40,3); cout<<"Testing..."; cout<<"Defaults!" << endl; cout << theRect(20,3,TRUE) << endl; }
here is the compiler results:
Code:--------------------Configuration: Default Values - Win32 Debug-------------------- Compiling... Default.cpp d:\my visual c++ projects\myprojects\default values\default.h(43) : error C2065: 'Height' : undeclared identifier d:\my visual c++ projects\myprojects\default values\default.h(44) : error C2065: 'Width' : undeclared identifier d:\my visual c++ projects\myprojects\default values\default.cpp(13) : error C2064: term does not evaluate to a function Error executing cl.exe. Default Values.exe - 3 error(s), 0 warning(s)
The error is somewhere in the default.cpp, i'll comment the line where the error's are show to be at! thanks for listeining![]()




Reply With Quote