首页 > OOP语言 > VC++ > 正文

MFC类库之CArray作为函数参数和返回值
2013-06-02 00:00:00   来源:www.bianceng.cn   评论:0 点击:

暂时无描述信息

一、获得返回值:

可以作为函数的一个参数

比如定义fun(CArray<int, int &> &array)

采用引用类型,就可以直接使用

二、作为函数参数:

#include<Afxtempl.h>    
//定义函数。   
void ansnode(int num,CArray<double,double&> m_adX, CArray<double,double&> m_adY, CArray<double,double&> m_adZ);

函数体:

void ansysdata::ansnode(int num,CArray<double,double&> *m_adX, CArray<double,double&> *m_adY, CArray<double,double&> *m_adZ)   
{   
       double x, y,z; int i;   
       fstream infilex;   
       fstream infiley;   
       fstream infilez;   
       infilex.open("d:/intface/M_ADX.TXT.txt",ios::in);    
       infiley.open("d:/intface/M_ADX.TXT.txt",ios::in);    
       infilez.open("d:/intface/M_ADX.TXT.txt",ios::in);    
       for (i=0;i<num;i++)   
       {   
           infilex>>x;   
           infiley>>y;   
           infilez>>z;   
           m_adX.Add(x);   
           m_adY.Add(y);    
           m_adZ.Add(z);   
       }   
       fstream outfilex;   
       fstream outfiley;   
       fstream outfilez;   
       outfilex.open("d:/intface/M_ADX1.TXT.txt",ios::in);    
       outfiley.open("d:/intface/M_ADX2.TXT.txt",ios::in);    
       outfilez.open("d:/intface/M_ADX3.TXT.txt",ios::in);    

       for (i=0;i<num;i++)   
      {   
          outfilex<<m_adX.GetAt(i)<<endl;    
          outfiley<<m_adY.GetAt(i)<<endl;   
          outfilez<<m_adZ.GetAt(i)<<endl;   
       }   
}

三、CArray结构体中的应用

struct DriverItem    
{    
     CString strDriverName;    
     CString strProductDescribe;    
     CString strTBLFileName;    
};    
struct ControlItem    
{    
      CString strControlType;    
      CArray <DriverItem,DriverItem&> DriverArray;    
};

相关热词搜索:

上一篇:VC中char和TCHAR的数据类型转换
下一篇:模态对话框与非模态对话的销毁方法与区别

分享到: 收藏