简体   繁体   English

关于将函数作为参数传递的好奇心-C ++

[英]Curiosity about passing a function as parameter - C++

suppose you have the following method: 假设您具有以下方法:

double * myMethod(double (*f)(double[]), double *x, int size)
{
    //do something and return
}

Why can't I write as follows? 我为什么不能写如下?

double * myMethod(double (*f)(double *), double *x, int size)
{
    //do something and return
}

replacing the [] with * ? 用*替换[]

You can, but because arrays deprecate the pointers, they actually have the same signature, so if you're getting an error it's because you're trying to redefine the function: 可以,但是由于数组不赞成使用指针,因此它们实际上具有相同的签名,因此,如果遇到错误,则是因为您正在尝试重新定义函数:

http://ideone.com/E1Z7B works because I renamed the second function. http://ideone.com/E1Z7B可以工作,因为我重命名了第二个功能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM