C++新手问题:编译时提示:[Linker error] undefined reference to `operato
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/06/16 10:03:12
C++新手问题:编译时提示:[Linker error] undefined reference to `operator*(double,complex c
我想写一个复数乘实数的函数(其中的复数是一个叫complex的class):
class complex
{
private:
double m_r; //实部
double m_i; //虚部
public:
complex operator*( double x) ;
friend complex operator*( double x,complex& st);
……剩下的省略
}
definition:
complex complex::operator*(double x)
{
complex result;
result.m_r=m_r*x;
result.m_i=m_i*x;
return result;
}
complex operator*(double x,complex& st)
{
return st*x;
}
但是编译时提示C++新手问题:下面的程序编译时提示 [Linker error] undefined reference to `operator*(double,complex c,如果我把两个函数的参数都改成const的,就可以顺利编译:
complex operator*(const double x) const ;
friend complex operator*(const double x,const complex& st);
我想写一个复数乘实数的函数(其中的复数是一个叫complex的class):
class complex
{
private:
double m_r; //实部
double m_i; //虚部
public:
complex operator*( double x) ;
friend complex operator*( double x,complex& st);
……剩下的省略
}
definition:
complex complex::operator*(double x)
{
complex result;
result.m_r=m_r*x;
result.m_i=m_i*x;
return result;
}
complex operator*(double x,complex& st)
{
return st*x;
}
但是编译时提示C++新手问题:下面的程序编译时提示 [Linker error] undefined reference to `operator*(double,complex c,如果我把两个函数的参数都改成const的,就可以顺利编译:
complex operator*(const double x) const ;
friend complex operator*(const double x,const complex& st);
你在调用*操作符的时候,参数可能是一个const类型的!而在你的定义中,参数是非const类型,编译器不确定你会不会修改参数的值,所以不会为你的const类型调用非const版本!
我想应该是这样的,不知道能不能帮到你
我想应该是这样的,不知道能不能帮到你
C++新手问题:编译时提示:[Linker error] undefined reference to `operato
[Linker error] undefined reference to `WinMain@16' 怎么办
C++undefined reference to `CreateList(SeqList*)是什么意思
以下是一个简单的小程序,gcc编译的时候提示undefined reference to `A::m',我想知道我错在哪
undefined reference to `sqrt'
undefined reference to 'pthread_create'是什么意思?
undefined reference
keil编译时出现reference made to unresolved external,
gtk 的错误undefined reference to `GTK_TEXT'
在用matlab解微分方程时提示如下信息:Input argument "y" is undefined.Error i
An undefined error has occured
在C语言编译时出现如下提示,点确定后又能够进行仿真,为什么?