问一个麻烦点的问题,请大家耐心看看,小弟谢谢了
c++吧
全部回复
仅看楼主
level 2
问一个麻烦点的问题 我把类的声放在一个。HPP的文件里,把类的定义放在一个。CPP的文件里 编译时,对书把能改的错误都改了,可是还是报错, 通不驼编译。是为什么? 作者: 天空飞鱼84 2007-3-7 07:47   回复此发言 -------------------------------------------------------------------------------- 2 回复:问一个麻烦点的问题 附程序,麻烦你看看了 这是类的声明 #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; }; 作者: 天空飞鱼84 2007-3-7 07:48   回复此发言 -------------------------------------------------------------------------------- 3 回复:问一个麻烦点的问题 类的定义 #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分 1
level 0
希望大家浪费点时间教教小弟
2007年03月07日 03点03分 2
level 7
你这也太粗心了吧,都是小错误Rect.hpp:int GetX()const (return itsX;}改为int GetX()const {return itsX;}Point itslowerLeft;Point itslowerRight;改为Point itsLowerLeft;Point 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 SetUpperLeft(Point Location) {itsUpperLeft = Location;} void SetLowerLeft(Point Location) {itsLowerLeft = Location;} void SetUpperRight(Point Location) {itsUpperRight = Location;} void SetLowerRight(Point Location) {itsLowerRight = Location;} void SetBottom(int bottom) { istBottom = bottom;} 改为void SetBottom(int bottom) { itsBottom = bottom;} Rect.cpp:int Recttangle::GetArea() const 改为int Rectangle::GetArea() const
2007年03月07日 04点03分 3
level 0
多谢大虾,呵呵,应该自己再仔细检查下
2007年03月07日 04点03分 4
1