1.cpp
#include <iostream>
using namespace std;
int a;
int main()
{extern int power(int);
int b=3,c,d,m;
cout<<"enter an integer a and its power m:"<<endl;
cin>>a>>m;
c=a*b;
cout<<a<<"*"<<b<<"="<<c<<endl;
d=power(m);
cout<<a<<"**"<<m<<"="<<d<<endl;
return 0;
}
2.cpp
extern int a;
int power(int n)
{int i,y=1;
for(i=1;i<=n;i++)
y*=a;
return y;
}
编译时出现错误:Linking...
xt4-16file1.obj : error LNK2001: unresolved external symbol "int __cdecl power(int)" (?power@@YAHH@Z)
Debug/xt4-16file1.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.