有一个对话框程序,在其中一个子程序A中需要使用到动态数组,包括一维的和二维的,应此就使用了vector,现在在这个子程序A中需要调用另外的子程序B进行计算,需要传递数组元素的值,请问应该如何进行。
请大家不吝赐教,回复时最好能用代码说明。
急用,在线等,麻烦大家了!!

解决方案 »

  1.   

    vector和动态数组一样用啊!&v[0]  ==  数组首址
      

  2.   

    子程序B定义一个参数,可以传vector也可以传元素,根据你的具体情况来定。
      

  3.   

    比如说:
    void CDlg1::programA() 
    {
         int n;
    n = 3;
    vector<vector<float> >  aa(n, vector<float>(n));
    vector<float>   b(n); 
    }void CDlg1::programB()
    {
        //如果想在此处来调用vector,代码应该怎么写?
    } 谢谢!!!
      

  4.   

    void CDlg1::programA()  

         int n; 
    n = 3; 
    vector <vector <float> >  aa(n, vector <float>(n)); 
    vector <float>   b(n);  
      programB(aa, b);
    } void CDlg1::programB(vector <vector <float> >& a2, vector <float>& b) 

        a2.xxx();
        b.yyy();
    }  
      

  5.   

    给programB定义参数,参考LS代码。
      

  6.   

    感谢几位的回答,我按照四楼的方法试了一下,结果报错,请帮忙看看原因因为还需要传递一个整型参数,我把B子程序声明为
    void COREV(vector <vector<float> >&aa, vector  <float>& b,int k); 在A里调用
    void CDlg1::programA()   {
        …………
        COREV(aa,b,i);
           ……………………
    }联接是就出现错误,信息如下
    error C2061: syntax error : identifier 'vector';
    error C2660: 'COREV' : function does not take 3 parameters;
    error C2511: 'COREV' : overloaded member function 'void (class std::vector<class std::vector<float,class std::allocator<float> >,class std::allocator<class std::vector<float,class std::allocator<float> > > > &,class std::vector<float,class std::allocator<float> > &,int)' not found in 'CKiPADlg'
      

  7.   

    CKiPADlg类中没有定义COREV函数,或者定义的参数与实现不同。
    另外#include <vector>最好放在stdafx.h里面。
      

  8.   

    请注意函数的命名空间要跟函数申明一致
    void CKiPADlg::COREV(...)
    {
      ...
    }