I am trying to pass array to function (*getcreditcurve). I am expecting function (*getcreditcurve) to return an array. Main function is expected to send several such array to function (*getcreditcurve), pointer function is expected to return a array to main function for different array using the logic given in pointer function (*getcreditcurve). however I get following error. Can somebody help in trouble shooting please? Sorry I went through other post/question in this site but not able to get simplest way to solve this issue. I am going to use this logic to build other projects so simplified the question just to resolve main issue.
'#include<iostream>
#include<cmath>
#include<fstream>
typedef double S1[5];
using namespace std;
double *getcreditcurve(double);
int main()
{
S1 C1, C2;
C1 = { 0.0029, 0.0039, 0.0046, 0.0052, 0.0057 };
C2 = { 0.0020, 0.0050, 0.0060, 0.0070, 0.0080 };
typedef double *issuer;
issuer I1 = getcreditcurve(C1);
issuer I2 = getcreditcurve(C2);
ofstream print;
print.open("result1.xls");
print << I1+1 << '\t' << I2+2 << endl;
print.close();
return 0;
}
double *getcreditcurve(double S1[5])
{
const int cp = 5;
typedef double curve[cp];
curve h;
h[0] = 2 * S1[0];
h[1] = 3 * S1[1];
h[2] = 4 * S1[2];
h[3] = 5 * S1[3];
h[4] = 6 * S1[4];
return h;
}'
1>------ Build started: Project: Project2, Configuration: Debug Win32 ------ 1> Source.cpp 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(12): error C3079: an initializer-list cannot be used as the right operand of this assignment operator 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(13): error C3079: an initializer-list cannot be used as the right operand of this assignment operator 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(16): error C2664: 'double *getcreditcurve(double)' : cannot convert argument 1 from 'S1' to 'double' 1> There is no context in which this conversion is possible 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(17): error C2664: 'double *getcreditcurve(double)' : cannot convert argument 1 from 'S1' to 'double' 1> There is no context in which this conversion is possible 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(42): warning C4172: returning address of local variable or temporary ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========