A
A. Name
Hello All,
I am having trouble trying to compile an example from the Sam's 21
days series. The error is "'Rectangle' undeclared (first use this
function)"
I have even dowloaded and tried to compile there version of the code
and still receive the same error.
Any help would be appreciated.
Code Example. Listing 8.8
// Using the "this" Pointer
#include <iostream.h>
using std::cout;
class Rectangle
{
public:
Rectangle(); // constructor
~Rectangle(); // deconstructor
void SetLength(int length) { this->itsLength = length; }
int GetLength() const { return this->itsLength; }
void SetWidth(int width) { itsWidth = width; }
int GetWidth() const { return itsWidth; }
private:
int itsLength;
int itsWidth;
};
Rectangle::Rectangle()
{
itsWidth = 5;
itsLength = 10;
}
Rectangle::~Rectangle()
{}
int main()
{
Rectangle theRect;
cout << "theRect is " << theRect.GetLength() << " feet long.\n";
cout << "theRect is " << theRect.GetWidth() << " feet wide.\n\n";
cout << "We are now changing the attributes of theRect.\n\n";
theRect.SetLength(20);
theRect.SetWidth(10);
cout << "theRect is now " << theRect.GetLength() << " feet
long.\n";
cout << "theRect is now " << theRect.GetWidth() << " fee
wide.\n\n";
return 0; // application termination
}
I am having trouble trying to compile an example from the Sam's 21
days series. The error is "'Rectangle' undeclared (first use this
function)"
I have even dowloaded and tried to compile there version of the code
and still receive the same error.
Any help would be appreciated.
Code Example. Listing 8.8
// Using the "this" Pointer
#include <iostream.h>
using std::cout;
class Rectangle
{
public:
Rectangle(); // constructor
~Rectangle(); // deconstructor
void SetLength(int length) { this->itsLength = length; }
int GetLength() const { return this->itsLength; }
void SetWidth(int width) { itsWidth = width; }
int GetWidth() const { return itsWidth; }
private:
int itsLength;
int itsWidth;
};
Rectangle::Rectangle()
{
itsWidth = 5;
itsLength = 10;
}
Rectangle::~Rectangle()
{}
int main()
{
Rectangle theRect;
cout << "theRect is " << theRect.GetLength() << " feet long.\n";
cout << "theRect is " << theRect.GetWidth() << " feet wide.\n\n";
cout << "We are now changing the attributes of theRect.\n\n";
theRect.SetLength(20);
theRect.SetWidth(10);
cout << "theRect is now " << theRect.GetLength() << " feet
long.\n";
cout << "theRect is now " << theRect.GetWidth() << " fee
wide.\n\n";
return 0; // application termination
}