Results 1 to 7 of 7

Thread: 3 smiple errors but i cna't figure it out!

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question 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

  2. #2
    Megatron
    Guest
    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! 
    	}

  3. #3
    Megatron
    Guest
    And this should fix your 3rd one.
    Code:
    void main()
    {
    	Rectangle theRect(40,3);
    
    	cout<<"Testing...";
    	cout<<"Defaults!" << endl;
    	theRect.DrawShape(20,3,TRUE);
    }

  4. #4

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Thumbs up thanks alot!!

    Your corrections worked great!!
    thank you!

  5. #5
    Megatron
    Guest
    You welcome.

    BTW: Is this code snippet from the book "C++ in 21 Days" ?

  6. #6

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    indeed...

    Yes it was...I was re-creating it to see if i rember what was going on.

  7. #7
    Megatron
    Guest
    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
  •  



Click Here to Expand Forum to Full Width