| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 453 人关注过本帖
标题:[求助]看看这个程序,为什么有错误
只看楼主 加入收藏
hitlfy
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2006-9-8
收藏
 问题点数:0 回复次数:2 
[求助]看看这个程序,为什么有错误
我是在VC++6.0上运行的,结果发现3处错误,2处警告,实在没想明白,请高手指教.
#include <iostream>
using namespace std;
class point
{
public:
point(float,float);
void setpoint(float,float);
float getX() const {return x;}
float getY() const {return y;}
friend ostream & operator<<(ostream &,const point &);
protected:
float x,y;
};
void point::setpoint(float a,float b)
{
x=a;y=b;
}
point::point(float a,float b)
{
x=a;y=b;
}
ostream & operator<<(ostream &output,const point &p)
{
output<<"["<<p.x<<","<<p.y<<"]"<<endl;
return output;
}
int main()
{
point p1(3.5,4.6);
cout<<"x="<<p1.getX()<<",y="<<p1.getY()<<endl;
p1.setpoint(8.5,6.8);
cout<<"p(new):"<<p1<<endl;
return 0;
}
2006-09-20 21:04
wangyou
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-5-1
收藏
得分:0 
回复:(hitlfy)[求助]看看这个程序,为什么有错误
大 哥,这可是在 书上就有的啊 ,光盘里有代码!!!
2006-09-20 21:23
虫虫飞ya飞
Rank: 1
等 级:新手上路
帖 子:122
专家分:0
注 册:2005-11-28
收藏
得分:0 

#include <iostream>
using namespace std;
class point
{
public:
point(double,double);
void setpoint(double,double);
double getX() const {return x;}
double getY() const {return y;}
friend ostream & operator<<(ostream &,const point &);
protected:
double x,y;

};
void point::setpoint(double a,double b)
{
x=a;y=b;
}
point::point(double a,double b)
{
x=a;y=b;
}
ostream & operator<<(ostream &output,const point &p)
{
output<<"["<<p.getX()<<","<<p.getY()<<"]"<<endl;
return output;
}

int main()
{
point p1(3.5,4.6);
cout<<"x="<<p1.getX()<<",y="<<p1.getY()<<endl;
p1.setpoint(8.5,6.8);
cout<<"p(new):"<<"x="<<p1.getX()<<",y="<<p1.getY()<<endl;
return 0;
}
这样就可以了


2006-09-21 19:02
快速回复:[求助]看看这个程序,为什么有错误
数据加载中...
 
   



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

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