| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 472 人关注过本帖
标题:[求助]程序的编译通不过了
只看楼主 加入收藏
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
 问题点数:0 回复次数:5 
[求助]程序的编译通不过了

按教程上的写了个类组合小程序,在编译的时候通不过了,请教各位,是哪里错了呢?要怎么改?
程序如下:

#include<iostream>
#include<math.h>
using namespace std;

class Poing
{private:
float x,y;//点的坐标
public:
Point(float xx,float yy)
{cout<<"point构造函数"<<endl;
x=xx;y=yy;
}
Point(Point &p)
{x=p.x;y=p.y;
cout<<"Point拷贝构造函数"<<endl;
}
float GetX(void){return x;}
float GetY(void){return y;}
};

class Distance
{
private:
Point p1,p2;
double dist;
public:
Distance(Point a,Point b);
double GetDis(void){return dist;};
}
Distance::Distance(Point a,Point b):p1(a),p2(b)
{cout<<"Distance构造函数"<<endl;
double x=double(p1.GetX()-p2.GetX());
double y=double(p1.GetY()-p2.GetY());
dist=sqrt(x*x+y*y);
}
void main()
{
Point myp1(1,1),myp2(4,5);
Distance myd(myp1,myp2);
cout<<"the distance is:";
cout<<myd.GetDis()<<endl;
}

就是这个小程序啦:)
会的朋友一定帮忙哟,请你喝酒

搜索更多相关主题的帖子: private include public 
2007-01-10 21:21
slowlybear
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-10-18
收藏
得分:0 

貌似友元函数的问题。。。还无解,高手来赐教。。。


2007-01-10 22:39
lzz4438253
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2007-1-4
收藏
得分:0 

#include<iostream>
#include<math.h>
using namespace std;

class Point
{
private:
float x,y;//点的坐标
public:
Point(float xx,float yy)
{
cout<<"point构造函数"<<endl;
x=xx;y=yy;
}
Point(const Point &p);

float GetX(void){return x;}
float GetY(void){return y;}
};

Point::Point(const Point &p)
{x=p.x;y=p.y;
cout<<"Point拷贝构造函数"<<endl;
}

class Distance
{
private:
Point p1,p2;
double dist;
public:
Distance(Point a,Point b);
double GetDis(void){return dist;};
};
Distance::Distance(Point a,Point b):p1(a),p2(b)
{
cout<<"Distance构造函数"<<endl;
double x=double(p1.GetX()-p2.GetX());
double y=double(p1.GetY()-p2.GetY());
dist=sqrt(x*x+y*y);
}

void main()
{
Point myp1(1,1),myp2(4,5);
Distance myd(myp1,myp2);
cout<<"the distance is:";
cout<<myd.GetDis()<<endl;
}


2007-01-10 23:01
lzz4438253
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2007-1-4
收藏
得分:0 
  这是我就你那个程序改了点..可以通过了..

2007-01-10 23:01
lzz4438253
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2007-1-4
收藏
得分:0 

#include<iostream>
#include<math.h>
using namespace std;

class Poing
{private:
float x,y;//点的坐标
public:
Point(float xx,float yy)
{cout<<"point构造函数"<<endl;
x=xx;y=yy;
}
Point(Point &p)
{x=p.x;y=p.y;
cout<<"Point拷贝构造函数"<<endl; //拷贝构造建议你写在外面...
}
float GetX(void){return x;}
float GetY(void){return y;}
};

class Distance
{
private:
Point p1,p2;
double dist;
public:
Distance(Point a,Point b);
double GetDis(void){return dist;};
}; //少了个分号..
Distance::Distance(Point a,Point b):p1(a),p2(b)
{cout<<"Distance构造函数"<<endl;
double x=double(p1.GetX()-p2.GetX());
double y=double(p1.GetY()-p2.GetY());
dist=sqrt(x*x+y*y);
}
void main()
{
Point myp1(1,1),myp2(4,5);
Distance myd(myp1,myp2);
cout<<"the distance is:";
cout<<myd.GetDis()<<endl;
}


2007-01-10 23:03
dubaoshi
Rank: 1
等 级:新手上路
帖 子:118
专家分:0
注 册:2006-9-22
收藏
得分:0 

谢谢楼上的朋友,现存编译是通过了,可是又连接不上呢呀。下面是提示
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/111.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

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


人行善,福虽未至,祸已远离;人行恶,祸虽未至,福已远离.
2007-01-11 23:16
快速回复:[求助]程序的编译通不过了
数据加载中...
 
   



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

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