标题:关于c++问题,出现了m2.cpp(41) : fatal error C1004: unexpected end of f ...
只看楼主
c718382171
Rank: 2
等 级:论坛游民
帖 子:32
专家分:41
注 册:2013-12-21
结帖率:83.33%
已结贴  问题点数:10 回复次数:3 
关于c++问题,出现了m2.cpp(41) : fatal error C1004: unexpected end of file found 执行 cl.ex
#include <iostream>
using namespace std;
class Point
{
public:
  Point(int x = 0, int y = 0):x_(x), y_(y){}
  int X()const{return x_;}
  int Y()const{return y_;}
  void X(int x){ x_ = x; }
  void Y(int y){ y_ = y; }
private:
  int x_;
  int y_;
};

class Rectangle
{
public:
  Rectangle(Point l, Point r) :ld(l), ru(r){}
  int Area(){ return (ru.x - ld.x) * (ru.y - ld.y);
  void Coord(){
    cout<<"Point 1: "<<ld.x<<","<<ld.y<<endl;
    cout<<"Point 2: "<<ru.x<<","<<rd.y<<endl;
    cout<<"Point 3: "<<ru.x<<","<<ru.y<<endl;
    cout<<"Point 1: "<<ld.x<<","<<ru.y<<endl;
  
  }
private:
  Point ld; //左下角的点
  Point ru; //右上角的点
};

int main()
{
  Point one(1, 1), two(10,10);
  Rectangle r(one, two);
  cout<<r.Area()<<endl;
  r.Coord();
  return 0;
}
搜索更多相关主题的帖子: unexpected private include public return 
2014-03-15 20:34
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:0 
#include <iostream>
using namespace std;
class Point
{
public:
  Point(int x = 0, int y = 0):x_(x), y_(y){}
  int X()const{return x_;}
  int Y()const{return y_;}
  void X(int x){ x_ = x; }
  void Y(int y){ y_ = y; }
private:
  int x_;
  int y_;
};

class Rectangle
{
public:
  Rectangle(Point l, Point r) :ld(l), ru(r){}
  int Area(){ return (ru.x - ld.x) * (ru.y - ld.y); // 这行你漏了一个右括号了
  void Coord(){
    cout<<"Point 1: "<<ld.x<<","<<ld.y<<endl;
    cout<<"Point 2: "<<ru.x<<","<<rd.y<<endl;     rd是什么?有这个对象吗?
    cout<<"Point 3: "<<ru.x<<","<<ru.y<<endl;     注意这个红快和上面的那行红快,x,y 这两个变量,ru 和ld 有这个成员吗?那边是x_ 和y_。
                                                  同时,那边权限是private:的。你明白private: 和public的差别不?
    cout<<"Point 1: "<<ld.x<<","<<ru.y<<endl;

  
  }
private:
  Point ld; //左下角的点
  Point ru; //右上角的点
};

int main()
{
  Point one(1, 1), two(10,10);
  Rectangle r(one, two);
  cout<<r.Area()<<endl;
  r.Coord();
  return 0;
}

我行我乐
我的博客:
http://blog.yuccn. net
2014-03-16 21:12
hubinyes
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:104
专家分:557
注 册:2014-2-4
得分:10 
楼上正解,,顶
2014-03-20 09:52
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:0 
这哥们结贴有意思~

我行我乐
我的博客:
http://blog.yuccn. net
2014-03-21 12:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-428573-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.263445 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved