2016-12-05 52 views
0

嘗試的成員找出爲什麼即時得到一個錯誤:未解析的外部主要參考在功能編譯器不能識別呼叫從類用作

頭文件:的

#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 

CPP文件包含函數定義surgery.h類的頭文件: 我覺得好像在即時通訊一個完整的丟失,因爲我一直在做這個了大量的時間

#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; 
} 

回答

0

您需要定義函數「主」的地方,這是流程

+0

你好切入點,並感謝您的答覆!我有一個主要聲明,但是當我在main調用該函數時,它說該函數不是成員。 –

+0

我的主看起來像這樣 –

+0

我在代碼的其餘部分添加了上面的主要內容。 –