我用MFC做了一个界面 其中我自己定义了一个函数A 而函数A 需要调用我自己定义的 四个函数B、C、D、E其中一个 在OnDraw函数中再调用函数A 。可是B、C、D、E我希望返回数组的值,其实这个数组是个4×4的矩阵,可是 我不会返回数组的值。可否指教?
解决方案 »
- VC静态库中的资源,如何与调用该库的工程中的资源整合?
- com口读取问题
- MFC创建ActiveX控件的属性修改问题
- Webbrowser 的 put_Resizable 只是控制的用户使用鼠标进行窗口大小的改变?
- 请问如何为透明画刷指定颜色
- directx9.0c以后已经不包含directshow了,如果要做开发,选9.0b好还是9.0c DX再另外下dshow?
- 这个dll该如何调试
- 用过 CTypedPtrArray 的请帮一忙!
- 如何使用ShellExcute 让程序运行起来呢?
- HOOK VsFlexGrid 的右键菜单的问题
- 关于GDI+ DrawString输出文字,中英文混合,字符串间距变化的问题
- GDI+的一段代码
void SetArray(*Carray)
注意变量的生存周期
{
int hijklmn[4][4];
}
void 函数B(参数1,参数2)
{
double temp1[4][4];
算法。
}
函数C、D、E同理
double A( 参数a , 参数b)
{ double temp1[4][4];
if(strcom.Compare("hz")==0)
{
B(m_hzvalue,stredit);
}
else if(strcom.Compare("lj")==0)
{
C(m_ljvalue);
}
else if(strcom.Compare("yb")==0)
{
D(m_ybvalue,stredit); } else if(strcom.Compare("yd")==0)
{
E(m_ydvalue,stredit);
}
//return temp[4][4];}
说我应该有返回值的 可是我也不会怎么返回啊
void 函数B(参数1,参数2)
{
double temp1[4][4];
算法。
}
函数C、D、E同理
double A( 参数a , 参数b)
{
double temp1[4][4];
if(strcom.Compare("hz")==0)
B(m_hzvalue,stredit);
else if(strcom.Compare("lj")==0)
C(m_ljvalue); else if(strcom.Compare("yb")==0)
D(m_ybvalue,stredit); else if(strcom.Compare("yd")==0)
E(m_ydvalue,stredit);
}
建议:你在A中定义double temp1[4][4];BCDE均增加一个参数,接受这个数组即可简化一点,用double[16]一维数组你在A定一个数组,然后BCDE各返回一个赋给A 毫无意义
在A函数中定义double temp1[4][4];在BCDE中又各自定义了double temp1[4][4]; 我想你是尝试把BCDE 中填充的temp1传递给A中的temp1吧?如果是元类型 double int 这个是可行的,但是对数组无需这样处理,把A的数组首地址直接传递给各个函数,让算法函数填充这个数组即可,处理完毕返回A的数组就有值了毫无意义是指:如果你是从BCDE返回一个数组赋给A的temp1,那么你A定义的double temp1[4][4]实际上没有任何意义;另外如果是返回函数内部定义的数组,可能会返回警告信息
在A函数中定义double temp1[4][4];在BCDE中又各自定义了double temp1[4][4]; 我想你是尝试把BCDE 中填充的temp1传递给A中的temp1吧?如果是元类型 double int 这个是可行的,但是对数组无需这样处理,把A的数组首地址直接传递给各个函数,让算法函数填充这个数组即可,处理完毕返回A的数组就有值了毫无意义是指:如果你是从BCDE返回一个数组赋给A的temp1,那么你A定义的double temp1[4][4]实际上没有任何意义;另外如果是返回函数内部定义的数组,可能会返回警告信息
算法函数怎么填充数组呢? 可否加个qq? 这么说太慢了
不用麻烦了,我给你写个例子
void A();double B(double para1,double para2,double* array2Fill);void A()
{
double Array[16]; //此数组有值,但值不可知
B(1.0,2.0,Array);
for(int i=0;i<4;i++) //Row
{
for(int j=0;i<4;j++) //Column
{
printf("%f\t",Array[i*4+j]);
}
printf("\n");
}
}double B(double para1,double para2,double* array2Fill)
{
//do something here
//set Array Value
for(int i=0;i<4;i++) //Row
{
for(int j=0;i<4;j++) //Column
{
//构造单位矩阵, 按你的算法处理各行各列的值
if(i==j)
array2Fill[i*4+j]=1;
else
array2Fill[i*4+j]=0;
}
}
return -1;
}
不用麻烦了,我给你写个例子
void A();double B(double para1,double para2,double* array2Fill);void A()
{
double Array[16]; //此数组有值,但值不可知
B(1.0,2.0,Array);
for(int i=0;i<4;i++) //Row
{
for(int j=0;i<4;j++) //Column
{
printf("%f\t",Array[i*4+j]);
}
printf("\n");
}
}double B(double para1,double para2,double* array2Fill)
{
//do something here
//set Array Value
for(int i=0;i<4;i++) //Row
{
for(int j=0;i<4;j++) //Column
{
//构造单位矩阵, 按你的算法处理各行各列的值
if(i==j)
array2Fill[i*4+j]=1;
else
array2Fill[i*4+j]=0;
}
}
return -1;
}
不用麻烦了,我给你写个例子
void A();double B(double para1,double para2,double* array2Fill);void A()
{
double Array[16]; //此数组有值,但值不可知
B(1.0,2.0,Array);
for(int i=0;i<4;i++) //Row
{
for(int j=0;i<4;j++) //Column
{
printf("%f\t",Array[i*4+j]);
}
printf("\n");
}
}double B(double para1,double para2,double* array2Fill)
{
//do something here
//set Array Value
for(int i=0;i<4;i++) //Row
{
for(int j=0;i<4;j++) //Column
{
//构造单位矩阵, 按你的算法处理各行各列的值
if(i==j)
array2Fill[i*4+j]=1;
else
array2Fill[i*4+j]=0;
}
}
return -1;
}
// rr.cpp : Defines the entry point for the console application.
//#include "stdafx.h"void A();
double B(double para1,double para2,double* array2Fill);void A2();
double B2(double para1,double para2,double array2Fill[][4]);void A()
{
double Array[16]; //此数组有值,但值不可知
B(1.0,2.0,Array);
for(int i=0;i<4;i++) //Row
{
for(int j=0;j<4;j++) //Column
{
printf("%f\t",Array[i*4+j]);
}
printf("\n");
}
}double B(double para1,double para2,double* array2Fill)
{
//do something here
//set Array Value
for(int i=0;i<4;i++) //Row
{
for(int j=0;j<4;j++) //Column
{
//构造单位矩阵, 按你的算法处理各行各列的值
if(i==j)
array2Fill[i*4+j]=1;
else
array2Fill[i*4+j]=0;
}
}
return -1;
}void A2()
{
double Array[4][4]; //此数组有值,但值不可知
B2(1.0,2.0,Array);
for(int i=0;i<4;i++) //Row
{
for(int j=0;j<4;j++) //Column
{
printf("%f\t",Array[i][j]);
}
printf("\n");
}
}double B2(double para1,double para2,double array2Fill[][4])
{
//do something here
//set Array Value
for(int i=0;i<4;i++) //Row
{
for(int j=0;j<4;j++) //Column
{
//构造单位矩阵, 按你的算法处理各行各列的值
if(i==j)
array2Fill[i][j]=1;
else
array2Fill[i][j]=0;
}
}
return -1;
}int main(int argc, char* argv[])
{
A2();
return 0;
}1.000000 0.000000 0.000000 0.000000
0.000000 1.000000 0.000000 0.000000
0.000000 0.000000 1.000000 0.000000
0.000000 0.000000 0.000000 1.000000
Press any key to continue
不能返回函数局部变量首地址你能不能看明白下面的两个函数的区别,看不明白,你还是找本C语言书从头看一下吧
double add(double a,double b)
{
return a+b;
}void add(double a,double b,double &result)
{
result = a+b;
}