void run1()
void run2()int main(){
............}
void run1(){
.............for(int i=1;i<59; i++ ) {
T=1;
tempT.push_back(T);
}
void run2(){在此子程序内可应用数组tempT}
void run2()int main(){
............}
void run1(){
.............for(int i=1;i<59; i++ ) {
T=1;
tempT.push_back(T);
}
void run2(){在此子程序内可应用数组tempT}
temp[]又不是全局变量是吧!
void run2(int* myArray);
调用:
run2(tempT);
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)请问怎样解决问题?
void run2(int A,int* tempT){//??????
void run1()
void run2()int main(){
run1();
run2();
}2)传递一个数组的引用参数指针如定义: void run2(int* myArray);
调用 :
run1()
{
int iArray[1024];
...
run2(&iArray);
...
}
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);
}
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);//改正了!
}
俺觉得这样用更合适一些,注意其中的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;
}
#include <vector>
using namespace std;typedef vector<int> myIntvector;
函数定义
run2(myIntvector& InParam);
调用:
run2(tempT);