【问题标题】:compiler is not recognizing call to function from class as member of class编译器没有将类中的函数调用识别为类的成员
【发布时间】: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


    【解决方案1】:

    你需要在某处定义函数'main',这是进程的入口点

    【讨论】:

    • 您好,感谢您的回复!我声明了一个 main,但是当我在 main 中调用该函数时,它说该函数不是成员。
    • 我的主要是这样的
    • 我还删除了变量的朋友和“静态”部分。
    • @K.kisner 使用surgeries.requestInput(),而不是surgerise::requestInput()
    • 太棒了!谢谢。仍然遇到问题,但它已编译。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多