它不是编译.我正在调用一个通过引用调用的函数,但有一个错误,无法将双*转换为双倍

it is not compiling. I am calling a function which is called by reference but there is an error which is can not convert double * to double

本文关键字:调用 有一个 错误 函数 转换 编译 一个 引用      更新时间:2023-10-16
#include<iostream.h>
#include<conio.h>
void square(double);
void main()
{
  clrscr();
  double x;
  x=123.456;
  cout<<"nThe value of i before calling square(), is :"<<x;
  cout<<endl;
  square(&x);
  cout<<"The value of i after calling square(), is :"<<x;
  cout<<endl;
  getche();
}
void square(double* x)
 {
  *x=*x**x;
 }

它不起作用,为什么?

它也没有编译。

我正在调用一个called by reference有一个错误,即

无法将双 * 转换为双倍

square的声明和定义在参数类型上有所不同:

void square(double);
// ...
void square(double* x) { /* ... */ }

square(&x)尝试使用double*调用void square(double) - 这解释了您的错误。


您还使用了古老的C++编译器 - iostream.hconio.h是非标准且过时的。

您对指针的使用也是非惯用的 - square应按值或const值引用double

相关文章: