| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 368 人关注过本帖
标题:求助
只看楼主 加入收藏
wangweiliang
Rank: 1
来 自:湖北
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-9-20
收藏
 问题点数:0 回复次数:1 
求助
请教高手,该程序如何改正.编绎时出现如下错误
F:\C++程序设计\summer programming\未完成\point\point.cpp(15) : fatal error C1001: INTERNAL COMPILER ERROR
        (compiler file 'msc1.cpp', line 1786)
         Please choose the Technical Support command on the Visual C++
         Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.

point.exe - 1 error(s), 0 warning(s)

#include<iostream>
using namespace std;
class Point
{
public:
    Point()
    {
    }
    Point(double a,double b)
    {
        x=a;
        y=b;
    }
    friend Point operator +(Point &p1,Point &p2)
    {
        Point temp;
        temp.x=p1.x+p2.x;
        temp.y=p1.y+p2.y;
        return temp;
    }
    friend Point operator -(Point &p1,Point &p2)
    {
        Point temp;
        temp.x=p1.x-p2.x;
        temp.y=p1.y-p2.y;
        return temp;
    }
    bool operator ==(Point &s)
    {
        if(x=s.x&&y=s.y)
            return true;
        else
            return false;
    }
    bool operator !=(Point &s2)
    {
        if(x=s2.x&&y=s2.y)
            return false;
        else
            return true;
    }

    void display()
    {
        cout<<"("<<x<<","<<y<<")"<<endl;
    }
private:
    double x;
    double y;
};
void main()
{
    Point s1(2.1,3.3),s2(3.2,4.4),s3(2.2,3.5),s4(5.9,7.3);
    Point s,p;
    s=s1+s2;
    s.display();
    p=s1-s2;
    p.display();
    cout<<(s1==s3)<<endl;
    cout<<(s1!=s4)<<endl;
}
2008-09-21 14:24
chenlou
Rank: 1
来 自:湖北黄冈武穴
等 级:新手上路
威 望:2
帖 子:49
专家分:0
注 册:2008-9-21
收藏
得分:0 
这是我根据你的程序修改后的程序,结果运行正确
#include<iostream>
using namespace std;
class Point
{
public:
    Point()
    {
    }
    Point(double a,double b)
    {
        x=a;
        y=b;
    }
     Point operator +(Point &p2)
    {
        Point temp;
        temp.x=x+p2.x;
        temp.y=y+p2.y;
        return temp;
    }
     Point operator -(Point &p2)
    {
        Point temp;
        temp.x=x-p2.x;
        temp.y=y-p2.y;
        return temp;
    }
    bool operator ==(Point &s)
    {
        if(x==s.x&&y==s.y)
            return true;
        else
            return false;
    }
    bool operator !=(Point &s2)
    {
        if(x==s2.x&&y==s2.y)
            return false;
        else
            return true;
    }

    void display()
    {
        cout<<"("<<x<<","<<y<<")"<<endl;
    }
private:
    double x;
    double y;
};
void main()
{
    Point s1(2.1,3.3),s2(3.2,4.4),s3(2.2,3.5),s4(5.9,7.3);
    Point s,p;
    s=s1+s2;
    s.display();
    p=s1-s2;
    p.display();
    cout<<(s1==s3)<<endl;
    cout<<(s1!=s4)<<endl;
}
我给你错误做以下总结:
1.友元函数可以是普通函数也可以是其他类的成员函数,但不能是本类的成员函数,没有把本类成员函数声明为友元函数的做法;
2.对于成员函数Point operator +(Point &p2)或者 Point operator -(Point &p2)只需一个参数,因为在进行s1+s2、s1-s2时是这样调用的:s1.operator +(s2)、s1.operator -(s2);
3.在判断两个数相等时应该用"=="而非"=";
2008-09-21 23:16
快速回复:求助
数据加载中...
 
   



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

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