【发布时间】:2015-07-11 22:49:37
【问题描述】:
我正在尝试将数组传递给函数 (*getcreditcurve)。我期待函数 (*getcreditcurve) 返回一个数组。主函数预计将几个这样的数组发送到函数(*getcreditcurve),指针函数预计使用指针函数(*getcreditcurve)中给出的逻辑将数组返回给不同数组的主函数。但是我收到以下错误。有人可以帮忙解决问题吗?抱歉,我浏览了此站点中的其他帖子/问题,但无法找到解决此问题的最简单方法。我将使用此逻辑来构建其他项目,从而简化问题只是为了解决主要问题。
'#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>----- 构建开始:项目:Project2,配置:调试 Win32 ------ 1> 源.cpp 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(12): error C3079: an initializer-list cannot be used as the right operation 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 operation of this assignment operator 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(16): 错误 C2664: 'double *getcreditcurve(double)' : 无法将参数 1 从 'S1' 转换为 'double' 1> 没有可以进行这种转换的上下文 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(17): 错误 C2664: 'double *getcreditcurve(double)' : 无法将参数 1 从 'S1' 转换为 'double' 1> 没有可以进行这种转换的上下文 1>c:\users\kdatta\documents\cqf\c++\project2\source.cpp(42): 警告C4172: 局部变量或临时返回地址 ========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
【问题讨论】:
-
我又来了 - 用缩进做 summat