const使用与否决定了程序能否运行,提示undefined reference to `show_polar(polar const*)'
/*
函数和结构的关系
*/
#include<iostream>
#include<cmath>
using namespace std;
struct polar
{
double distance;
double angle;
} ;
struct rect
{
double x;
double y;
};
void rect_to_polar(const rect * xypos, polar * pda);//把结果直接放到pda这个指针指向的结构中
void show_polar(const polar * dapos);//加const是因为不想修改这个结构
int main()
{
rect rplace;
polar pplace;
cout << "enter the x and y values: ";
while(cin >> rplace.x >> rplace.y)
{
//结构的地址不像数组,结构的地址是需要&地址操作符获得的
rect_to_polar(&rplace, &pplace);
show_polar(&pplace);
cout << "next ot numbers(q to quit): ";//其实任意一个非数字的字符都可以退出
}
cout << "done" << endl;
return 0;
}
//因为把结果直接放到了指针pda指向的内存中,所以不用返回polar结构了
void rect_to_polar(const rect * xypos, polar * pda)
{
pda->distance = sqrt(xypos->x * xypos->x + xypos->y * xypos->y);
pda-> angle = atan2(xypos->y, xypos->x);
}
void show_polar(polar * dapos)
{
const double Rad_to_deg = 57.29577951;
cout << "distance = " << dapos->distance;
cout << ", angle = " << dapos->angle * Rad_to_deg;
cout << " degress" << endl;
}
这一个程序我准备是在一本书上看到的,我运行的时候,如果void show_polar(const polar * dapos);这一条语句不加const的话可以正常运行,但是如果加了const的话,就提示undefined reference to `show_polar(polar const*)',应该是提示我没有使用引用,请教为什么会出现这样子的情况呢?