Greetings Everyone,
I'm in a bit of a fiddle in that I dont know why my code brings up the following error when compiling:
1>..\SA.cpp(81) : error C2664: 'CFE' : cannot convert parameter 1 from 'int' to 'int []'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Essentially I am trying to:
Step1: Convert from a vector to an array using:
int* VecToArray(vector<int> Vec)
{
int ary[Vec.size()];
for(int i = 0; i < Vec.size(); i++)
ary[i] = Vec[i];
return ary;
}
Step2: Calling upon a function into which the array is an paremeter and it returns a pointer from a newly generated array:
int* CFE(int density[])
{
...do stuff to generate 'double Energy[]'....
return Energy;
}
Step 3: Using this pointer in a third function to calcualte the sum of Energy[]:
double ObjFunction (double *E_Array)
{
double SumEnergy = 0;
int n = 10; // Is irrelivant
for (int i = 0; i < n; i++)
{
SumEnergy += E_Array[i];
}
return SumEnergy;
}
To make for simpler coding I've used the functions like so, where VectorName is an interger vector:
double TotalEnergy = ObjFunction ( CFE ( VecToArray ( VectorName ) ) );
I am obviously getting the parameter types wrong somewhere, though I just cant see why myself. Could anyone with a more experianced eye assist in spotting it/them?
Thank you.