#include<iostream>
#include<ctime>
using namespace std;
//----------------------------------------
int calc1(int a,int b)
{
return a+b;
}
//-----------------------------------------
inline int calc2(int a,int b)
{
return a+b;
}
//-----------------------------------------
void main()
{
int x[1000],y[1000],z[1000];
clock_t start,finish;
double dtime;
start = clock();
for(int i=0; i<1000; ++i)
for(int j=0; j<1000; ++j)
for(int k=0; k<1000; ++k)
z[i] = calc1(x[j],y[k]);
finish = clock();
dtime = finish - start;
cout<<"not using inline: "<<dtime<<" seconds\n";
start = clock();
for(int i=0; i<1000; ++i)
for(int j=0; j<1000; ++j)
for(int k=0; k<1000; ++k)
z[i] = calc2(x[j],y[k]);
finish = clock();
dtime = finish - start;
cout<<" using inline: "<<dtime<<" seconds\n";
} 怎么输不出结果,编译时i重定义了,没有重定义呀!谁能帮我分析以下.
using namespace std;
//----------------------------------------
int calc1(int a,int b)
{
return a+b;
}
//-----------------------------------------
inline int calc2(int a,int b)
{
return a+b;
}
//-----------------------------------------
void main()
{
int x[1000],y[1000],z[1000];
clock_t start,finish;
double dtime;
start = clock();
for(int i=0; i<1000; ++i)
for(int j=0; j<1000; ++j)
z[i] = calc1(x[i]y[j]);
finish = clock();
dtime = finish - start;
cout<<"not using inline: "<<dtime<<" seconds\n";
start = clock();
for( i=0; i<1000; ++i)
for(int j=0; j<1000; ++j)
z[i] = calc2(x[i],y[j]);
finish = clock();
dtime = finish - start;
cout<<" using inline: "<<dtime<<" seconds\n";
}修改后能输出结果了,但是有时使用内联函数运行所需的时间比不使用还要多,谁能解释以下.