它显示“链接器错误:致命错误 LNK1120: 1 unresolved externals”整个项目 = 头文件、第一个 .cpp 文件和第二个带有 main() 函数的 .cpp 文件。Any1 知道我做错了什么吗?
//golf.h for golf.cpp
const int Len = 40;
struct golf{
char fullname[Len];
int handicap;
};
//dla gotowych wartosci
void setgolf (golf & g, const char * name, int hc);
//do wpisywania wartosci
int setgolf (golf & g);
//tylko handicap
inline void handicap (golf & g, int hc);
//wyswietla info o graczu
void showgolf (const golf & g) ;
下一个文件
//golf.cpp for 9-1.cpp
#include <iostream>
#include <cstring>
#include "golf.h"
extern const int Len;
void setgolf (golf & g, const char* name, int hc){
strcpy(g.fullname,name);
g.handicap=hc;
}
int setgolf (golf & g){
using namespace std;
cout << "Podaj fullname golfiarza" << endl;
if (cin.getline(g.fullname,Len)) return 0;
cout << "Teraz podaj jego handicap" << endl;
cin >> g.handicap;
return 1;
}
inline void handicap (golf & g, int hc){
g.handicap=hc;
}
void showgolf (const golf & g){
using std::cout;
using std::endl;
cout << "Fullname gracza to: " << g.fullname << endl;
cout << "Jego handicap to: " << g.handicap << endl;
}
最后一个文件
#include <iostream>
#include <cstdlib>
#include "golf.h"
using namespace std;
int main(){
cout << "Witaj!\nTutaj program golficzny!" << endl;
golf filip;
golf klaudia;
cout << "Automatyczne uzupelnienie Filipa" << endl;
setgolf(filip, "Filip Bartuzi",100);
showgolf(filip);
cout << "Manualne uzupelnienie Klaudii" << endl;
((setgolf(klaudia))==1) ? showgolf(klaudia) : cout << "nie wprowadziles gracza!" << endl; ;
cout << "Zly handicap? Okey, zmienie handicap Filipowi" << endl;
handicap(filip,50);
showgolf(filip);
cout << "Od razu lepiej, nieprawda?" << endl;
system("PAUSE");
return 0;
}
任何的想法?