Original Post
Hi, currently I'm using a book to learn c++, the same book used in the cpp workshop on this forum and I'm having a problem with classes and headers. I have this listing from the book and I have errors. This is my header: // Begin Rectangle.h #include class Point // holds x,y coordinates { //no constructor, use default public: void SetX(int x) {itsX = x;} void SetY(int y) {itsY = y;} int GetX()const {return itsX;} int GetY()const {return itsY;} private: int itsX; int itsY; }; // end of point class declaration class Rectangle { public: Rectangle (int top, int left, int bottom, int right); ~Rectangle () {} int GetTop() const {return itsTop;} int GetLeft() const {return itsLeft;} int GetBottom() const {return itsBottom;} int GetRight() const {return itsRight;} Point GetUpperLeft() const {return itsUpperLeft;} Point GetLowerLeft() const {return itsLowerLeft;} Point GetUpperRight() const {return itsUpperRight;} Point GetLowerRight() const {return itsLowerRight;} void SetUpperLeft(Point Location) {itsUpperLeft;} void SetLowerLeft(Point Location) {itsLowerLeft;} void SetUpperRight(Point Location) {itsUpperRight;} void SetLowerRight(Point Location) {itsLowerRight;} void SetTop(int Top) {itsTop = Top;} void SetLeft(int Left) {itsLeft = Left;} void SetBottom(int Bottom) {itsBottom = Bottom;} void SetRight(int Right) {itsRight = Right;} int GetArea() const; private: Point itsUpperLeft; Point itsUpperRight; Point itsLowerLeft; Point itsLowerRight; int itsTop; int itsLeft; int itsBottom; int itsRight; }; // end rectangle.h ________________________________________________________________________________ ________________________________________________________________________________ and this is my source: // Begin Rect.cpp #include "Rectangle.h" Rectangle::Rectangle(int top, int left, int bottom, int right) { itsTop = top; itsLeft = left; itsBottom = bottom; itsRight = right; itsUpperLeft.SetX(left); itsUpperLeft.SetY(top); itsUpperRight.SetX(right); itsUpperRight.SetY(top); itsLowerLeft.SetX(left); itsLowerLeft.SetY(bottom); itsLowerRight.SetX(right); itsLowerLeft.SetY(bottom); } // compute area of the rectangle by finding sides, // establish width and height and then multiply int Rectangle::GetArea() const { int Width = itsRight-itsLeft; int Height = itsTop-itsBottom; return (Width*Height); } int main() { //intitialize a local Rectangle variable Rectangle MyRectangle(100, 20, 50, 80) int Area = MyRectangle.GetArea(); std::cout << "Area: " << Area << "\n"; std::cout << "Upper Left X: Coordinate: "; std::cout << MyRectangle.GetUpperLeft().GetX(); return 0; } ________________________________________________________________________________ ________________________________________________________________________________ I recieve the following errors: ------ Build started: Project: Studying, Configuration: Debug Win32 ------ Compiling... Rect.cpp c:\documents and settings\administrator\my documents\visual studio 2005\projects\studying\studying\rect.cpp(38) : error C2448: 'MyRectangle' : function-style initializer appears to be a function definition c:\documents and settings\administrator\my documents\visual studio 2005\projects\studying\studying\rect.cpp(38) : error C2065: 'MyRectangle' : undeclared identifier c:\documents and settings\administrator\my documents\visual studio 2005\projects\studying\studying\rect.cpp(38) : error C2228: left of '.GetArea' must have class/struct/union type is ''unknown-type'' c:\documents and settings\administrator\my documents\visual studio 2005\projects\studying\studying\rect.cpp(42) : error C2228: left of '.GetUpperLeft' must have class/struct/union type is ''unknown-type'' c:\documents and settings\administrator\my documents\visual studio 2005\projects\studying\studying\rect.cpp(42) : error C2228: left of '.GetX' must have class/struct/union Any help would be greatly appreciated, I've never seen the class/struct/union error before and I think its a typo in the code from the book or I made some stupid mistake. Sorry for such a long post. Thank You