问一个麻烦点的问题
福兴韵吧
全部回复
仅看楼主
level 1
我把类的声放在一个。HPP的文件里,把类的定义放在一个。CPP的文件里编译时,对书把能改的错误都改了,可是还是报错, 通不驼编译。是为什么?
2007年03月06日 23点03分 1
level 1
附程序,麻烦你看看了这是类的声明#include
class Point{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;};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 = Location;}void SetLowerLeft(Point Location) {itsLowerLeft = location;}void SetUpperRight(Point Location) {itsUpperRight = location;}void SetLowerRight(Point location) {itsLowerRight = location;}void SetTop(int top) { itsTop = top; }void SetLeft(int left) { itsLeft = left; } void SetBottom(int bottom) { istBottom = 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;};
2007年03月06日 23点03分 2
level 1
类的定义#include "Rect.hpp"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);itsLowerRight.SetY(bottom);}int Recttangle::GetArea() const{int Width = itsRight - itsLeft;int Height = itsTop - itsBottom;return (Width * Height);}int main(){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;}
2007年03月06日 23点03分 3
level 0
你看一下是不是写错了int GetX()const (return itsX;} 括号
2007年03月07日 09点03分 4
level 0
istBottom = bottom 也错了 ist 改为its
2007年03月07日 09点03分 5
1