void run1()
void run2()int main(){
............}
void run1(){
.............for(int i=1;i<59; i++ ) {
   
          T=1;        
tempT.push_back(T);
}
void run2(){在此子程序内可应用数组tempT}

解决方案 »

  1.   

    是啊!不往函数里传怎么用啊!
    temp[]又不是全局变量是吧!
      

  2.   

    定义:
    void run2(int* myArray);
    调用:
    run2(tempT);
      

  3.   

    我按你们的建议修改如下:void run1(int Q);
    void run2(int A,int* tempT);int main(){
    ............
     int Q=4;
     run1( Q );
     run2( A,tempT);}
    void run1(int Q){
    .............
    在此子程序内可产生数组tempT,数值A }
    void run2(int A,int* tempT){在此子程序内可调用数组tempT,数值A}但是在编译时,分别在????????标记出出现错误。: error C2664: 'run2' : cannot convert parameter 4 from 'class std::vector<int,class std::allocator<int> >' to 'int *'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called: error C2601: 'run2' : local function definitions are illegal: fatal error C1004: unexpected end of file found
    Error executing cl.exe..exe - 3 error(s), 0 warning(s)请问怎样解决问题?
      

  4.   

    run2( A,tempT);//??????????
    void run2(int A,int* tempT){//??????
      

  5.   

    1)可以用全局数组或包含在类里面的成员数组比如int m_myArray[1024];
    void run1()
    void run2()int main(){
    run1();
    run2();
    }2)传递一个数组的引用参数指针如定义: void run2(int* myArray);
    调用 :
    run1()
    {
       int iArray[1024];
    ...
       run2(&iArray);
    ...
    }
      

  6.   

    用指针:下面是我给别人写的一个测试小程序:#include<iostream.h>
    void f1(int *p,int n,int m)//
    {
      int i,j;
      for(i=0;i<n;i++)
       for(j=0;j<m;j++)
      {
      cout<<p[i*m+j];
      }
    }
    void main()
    {
      int a[3][4]={{1,2,3,4},
           {5,6,7,8},
           {9,0,1,2}};
      f1(a[0][0],3,4);
    }
      

  7.   

    不好意思,刚才写错了!#include<iostream.h>
    void f1(int *p,int n,int m)//
    {
      int i,j;
      for(i=0;i<n;i++)
       for(j=0;j<m;j++)
      {
      cout<<p[i*m+j];
      }
    }
    void main()
    {
      int a[3][4]={{1,2,3,4},
           {5,6,7,8},
           {9,0,1,2}};
      f1(&a[0][0],3,4);//改正了!
    }
      

  8.   

    看push_back知道楼主用的是stl,所以大家所说的直接用指针不一定会灵的
    俺觉得这样用更合适一些,注意其中的typedef#include <list>
    using namespace std;typedef list<int> IntList;void test1(IntList& lst)
    { }
    void test2(IntList* pLst)
    {}
    void test3(int* pInt)
    {}
    int main()
    {
    IntList lstX;
    lstX.push_back (10);
    lstX.push_back (11);
    test1(lstX);
    test2(&lstX);
    return 0;
    }
      

  9.   

    对了,楼主用的是vector,不过和list也没有什么区别
      

  10.   

    看了你的编译错误才知道你的数组是vector数组,那当然会出错了。
    #include <vector>
    using namespace std;typedef vector<int> myIntvector;
    函数定义
    run2(myIntvector& InParam);
    调用:
    run2(tempT);