简体   繁体   English

错误:无法将类型“ double *”的值分配给类型“ double”的实体

[英]Error: a value of type “double*” cannot be assigned to an entity of type “double”

I encountered a problem while i type my code. 输入代码时遇到问题。

...
double* FindMax(const double* const arr, int n)
{
    double max;
    ...
    return &max;
}

int main()
{
    ...
    maxVal = FindMax(value, numbers);
    ...
}

When I call the function FindMax, the program error and not allow me pass the value to function FindMax. 当我调用函数FindMax时,程序出错并且不允许我将值传递给函数FindMax。 How can I make it possible, thanks a lot! 我要如何使它成为可能,非常感谢!

Two things, if maxVal is double, you cannot assign value of &max . 两件事,如果maxVal为double,则无法分配&max It should be double * . 它应该是double *
Secondly, never return address of local variable. 其次,永远不要返回局部变量的地址。 Because once you return from function, local variable die. 因为一旦从函数返回,局部变量就会死亡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IntelliSense:不能将类型为“ void”的值分配给类型为“ double”的实体 - IntelliSense: a value of type “void” cannot be assigned to an entity of type “double” “void *”类型的值不能分配给“double *”类型的实体 - A value of type "void *" cannot be assigned to an entity of type "double *" 如何修复类型的值不能分配给错误类型的实体? - How to fix Value of type cannot be assigned to entity of type ERROR? 错误:无法将类型“ long *”的值分配给类型“ long”的实体 - Error: a value of type “long *” cannot be assigned to an entity of type “long” 不能将类型为“ Struct *”的值分配给类型为“ Struct *”的实体 - a value of type “Struct*” cannot be assigned to an entity of type “Struct*” 类型“ * const char *”的值不能分配给“ char *”类型的实体 - A value of type “*const char *” cannot be assigned to an entity of type “char *” C ++无法将类型为“ char”的值分配给类型为“ char *”的实体 - C++ a value of type “char” cannot be assigned to an entity of type “char *” “const”类型的值<Component> *”不能分配给类型为“的实体<Component> *” - A value of type “const <Component> *” cannot be assigned to an entity of type “<Component> *” “const char *”类型的值不能分配给“LPSTR”类型的实体 - Value of type "const char *" cannot be assigned to an entity of type "LPSTR" IntelliSense:无法将类型为“ IDeviceServer *”的值分配给类型为“ IDeviceServer *”的实体 - IntelliSense: a value of type “IDeviceServer *” cannot be assigned to an entity of type “IDeviceServer *”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM