问题描述
- c++类的组合 编译正确 组建错误
-
#include
#include
using namespace std;
class point
{
public:
void set();//设置原点坐标;;
void move();//移动距离;
void l(int x,int y);//移动后坐标及两点间距离;
int getx();
int gety();
private:
int x,y;
};
class line
{
public:
line(point a,point b);
void xl();//直线的斜率;
private:
point p1,p2;
};
main()
{
class point a,b;
class line l1(point a,point b);
cout<<"请设置直线上两点坐标:";
a.set();
b.set();
l1(a,b);
}
void point::set()
{
cin>>x;
cin>>y;
cout<<"点坐标为:("<
}
void point::move()
{
int m,n;
cin>>m;
cin>>n;
x=x+m;
y=y+n;
cout<<"移动后坐标为:("<<x<<","<<y<<")."<<endl;
cout<<"两点间距离为:"<<sqrt(m*m+n*n)<<endl;
}
int point::getx()
{
return x;
}
int point::gety()
{
return y;
}
line::line(point a,point b):p1(a),p2(b)
{
double k;
int m,n,p,q;
p1=a;
p2=b;
m=p1.getx();
n=p1.gety();
p=p2.getx();
q=p2.gety();
k=(n-q)/(m-p);
cout<<"直线的斜率为:"<<k<<endl;
}组建错误:
unresolved external symbol "class line __cdecl l1(class point,class point)" (?l1@@YA?AVline@@Vpoint@@0@Z)
解决方案
main函数里
l1(a,b);
这句是错误的,看看书上关于类的构造函数的介绍
时间: 2024-11-18 03:45:14