|
-
May 19th, 2001, 02:45 PM
#1
Thread Starter
Registered User
3 smiple errors but i cna't figure it out!
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
-
May 19th, 2001, 03:25 PM
#2
This should fix your 1st 2 errors.
Code:
if(CurrentDefault == TRUE)
{
PrintHeight = aHeight;
PrintWidth = aWidth;
}else{
PrintHeight = itsHeight; //errors found here
PrintWidth = istWidth; //and here!
}
-
May 19th, 2001, 03:29 PM
#3
And this should fix your 3rd one.
Code:
void main()
{
Rectangle theRect(40,3);
cout<<"Testing...";
cout<<"Defaults!" << endl;
theRect.DrawShape(20,3,TRUE);
}
-
May 20th, 2001, 01:41 PM
#4
Thread Starter
Registered User
thanks alot!!
Your corrections worked great!!
thank you!
-
May 21st, 2001, 10:19 AM
#5
You welcome.
BTW: Is this code snippet from the book "C++ in 21 Days" ?
-
May 21st, 2001, 02:40 PM
#6
Thread Starter
Registered User
indeed...
Yes it was...I was re-creating it to see if i rember what was going on.
-
May 21st, 2001, 03:35 PM
#7
I knew I remembered it from somewhere
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|