![](/img/trans.png)
[英]Measure function execution time in Visual Studio Enterprise 2017 (C++)
[英]Dynamics array from function to function in C visual studio 2017
我需要從一個函數轉移到另一個函數。 我像這樣嘗試:
double toarray(double x,int n)
{
double * results = new double[n];
for (int j = 0; j < n; j++)
{
results[j] = function( x);
x += jump;
}
return *results;
}
void showarr(double*arr[],int n,double x)
{
for(int i=0;i<n;i++)
{
printf("Wynik dla x=" "%.2lf", x);
if (denomcheck(x) == true && function(x)<INT_MAX)
{
printf(" | y=%.2lf \n", arr[i]);
}
else
printf(" | MIANOWNIK = 0!!! \n");
x += jump;
}
}
但是當我嘗試調用 toarray 作為 showarr 的變量時:
showarr(toarray(x, n), n, x);
我在 vs 2017 中收到 E0167 錯誤。
“參數類型“double”與參數類型“double **”不兼容
你的toarray
應該返回一個指向數組的指針,而不是一個雙toarray
值:
double *toarray(double x,int n) {
double * results = new double[n];
...
return results;
}
並且showarr
應該處理雙精度數組(作為指向此類數組的指針傳遞,可以寫為double arr[]
或double *
)而不是指向雙精度的指針數組(這就是double *arr[]
的含義) :
void showarr(double arr[],int n,double x) {
...
此外,您應該刪除您創建的數組,即在之后不需要arr
地方使用delete[] arr
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.