#include <iostream>
using namespace std;
void Accept(char &,int *,float *);
void Display(char *,int,float);
int main()
{char cName[20];
int iAge;
float fSalary;
Accept(cName[20],&iAge,&fSalary);
Display(cName,iAge,fSalary);
return 0;
}
void Accept(char Nam[20],int *Age_ptr,float *Sal)
{cout<<"请输入职员的姓名:\t";
cin>>Nam[20];
cout<<"请输入职员的年龄:\t";
cin>>*Age_ptr;
cout<<"请输入职员的月薪:\t";
cin>>*Sal;
}
void Display(char *Nam,int Age,float Sal)
{cout<<"\n…………显示个人信息……………"<<endl;
cout<<"\n职员的姓名是:\t"<<Nam<<endl;
cout<<"\n职员的年龄是:\t"<<Age<<endl;
cout<<"\n职员的薪水是:\t"<<Sal<<endl;
}
此程序在编译时通过,但在连接生成可执行文件却出现如下错误,请教高手指教一下,错在哪?如何修改?
Linking...
model.obj : error LNK2001: unresolved external symbol "void __cdecl Accept(char &,int *,float *)" (?Accept@@YAXAADPAHPAM@Z)
Debug/model.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
model.exe - 2 error(s), 0 warning(s)
參考答案:#include <iostream>
using namespace std;
void Accept(char *, int *, float *); //改成了char*,数组怎么能引用?给个数组首地址就是了
void Display(char *, int, float);
int main()
{
char cName[20];
int iAge;
float fSalary;
Accept(cName,&iAge,&fSalary); //改成了cName
Display(cName,iAge,fSalary);
return 0;
}
void Accept(char Nam[], int *Age_ptr, float *Sal)
{
cout<<"请输入职员的姓名:\t";
cin>>Nam; //改成了Nam
cout<<"请输入职员的年龄:\t";
cin>>*Age_ptr;
cout<<"请输入职员的月薪:\t";
cin>>*Sal;
}
void Display(char *Nam, int Age, float Sal)
{
cout<<"\n…………显示个人信息……………"<<endl;
cout<<"\n职员的姓名是:\t"<<Nam<<endl;
cout<<"\n职员的年龄是:\t"<<Age<<endl;
cout<<"\n职员的薪水是:\t"<<Sal<<endl;
}