【发布时间】:2017-04-19 07:33:18
【问题描述】:
试图找出为什么我得到一个错误:函数中未解析的外部主引用
头文件:
#define SURGERY_H
#include <string>
using namespace std;
class Surgery {
private:
static int didhave[5];
static float costs[5], total;
static string types[5];
public:
friend void requestInput();
friend float sendTotal();
};
static float costs[5] = { 100.00, 200.00, 300.00, 400.00, 500.00 };
static string types[5] = { "Tonsil", "Foot", "Knee", "Shoulder", "Appendix" } ;
static int didhave[5] = { 0, 0, 0, 0, 0 };
#endif
包含函数定义的 Surgery.h 类头文件的 cpp 文件: 我感觉自己好像完全迷失了,因为我已经为此工作了很长时间
#include <iostream>
#include "Surgery.h"
#include <string>
using namespace std;
void requestInput() {
string input;
while(input[0]!='1'){
cout << "Which types of surgery did the patient have? 1) for finished.\n";
cin >> input;
if(input[0]=='T' || input[0]=='t')
didhave[0]=1;
else if(input[0]=='F' || input[0]=='f')
didhave[1]=1;
else if(input[0]=='K' || input[0]=='k')
didhave[2]=1;
else if(input[0]=='S' || input[0]=='s')
didhave[3]=1;
else if(input[0]=='A' || input[0]=='a')
didhave[4]=1;
else
cout << "Invalid Surgery Type.";
}
}
float sendTotal() {
int i;
float total;
for(i=0; i<5; i++){
if(didhave[i]==1)
total+=costs[i];
}
return total;
}
主要:
#include <iostream>
#include "Surgery.h"
int main(void){
Surgery surgeries;
surgeries::requestInput();
system("pause");
return 0;
}
【问题讨论】:
标签: c++ file header implementation