求教关于类和对象的例子,求平面内两条直线的交点,已知直线斜截式方程
#include <iostream>using namespace std;
struct point
{
double x,y;//交点坐标
};
class line
{
private:
double m,b;//m为斜率,b为截距
point pt;//pt为交点
public:
void set_line_data();
void show_line_data();
void calc_pt(line);
};
void line::set_line_data()
{
cout<<"please input m(xielv):";
cin>>m;
cout<<"please input b(jieju):";
cin>>b;
}
void line::show_line_data()
{
cout<<"m="<<m<<",b="<<b<<endl;
}
void line::calc_pt()
{
pt.x=(crossing_line.b-b)/(m-crossing_line.m);
pt.y=m*pt.x+b;
cout<<"the two lines crossing point is:("<<pt.x<<","<<pt.y<<")"<<endl;
}
int main()
{
line line1,line2;
cout<<"please input line1:\n"; line1.set_line_data();
cout<<"please input line2:\n"; line2.set_line_data();
cout<<"line1:\n"; line1.show_line_data();
cout<<"line2:\n"; line2.show_line_data();
line1.calc_pt(line2);
return 0;
}
错误提示是:
--------------------Configuration: example2 - Win32 Debug--------------------
Compiling...
example2.cpp
d:\my_c_documents\example\example2.cpp(31) : error C2511: 'calc_pt' : overloaded member function 'void (void)' not found in 'line'
d:\my_c_documents\example\example2.cpp(9) : see declaration of 'line'
执行 cl.exe 时出错.
example2.obj - 1 error(s), 0 warning(s)