非标准语法,使用&创建指向成员的指针

时间:2019-12-05 23:18:01

标签: c++ function class pointers syntax-error

class calcBMI {
public:
    string line;
    string line2;
    fstream search;
    short loop = 0;
    string weight[6];
    string height[6];
    int index[6] = { 1, 2, 3, 4, 5 };
    int i;

    void getWeight() {

        search.open("name.txt"); //Opens the text file in which the user details are stored
        if (search.is_open())
        {
            while (getline(search, line)) { //While the program searches for the lines in the text file
                if (line.find("Current Weight(KG): ") != string::npos) { //If the string "Name" isnt the last word on the line
                    weight[loop] = line; //Assings the strings read from the text file to the array called weight
                    cout << index[loop] << ". " << weight[loop] << endl; //Outputs the index array which loops through the numbers in the array and outputs the weight variable which loops through the strings in the array
                    loop++; //Iterates the loop 
                }
            }
        }
    }

    void getHeight() {

        if (search.is_open())
        {
            while (getline(search, line2)) { //While the program searches for the lines in the text file
                if (line2.find("Height") != string::npos) { //If the string "Name" isnt the last word on the line
                    height[loop] = line2; //Assings the strings read from the text file to the array called weight
                    cout << index[loop] << ". " << height[loop] << endl; //Outputs the index array which loops through the numbers in the array and outputs the weight variable which loops through the strings in the array
                    loop++; //Iterates the loop 
                }
            }
        }
    }

    void calculateBMI() {

        calcBMI a;

        a.getWeight;
        a.getHeight;

    }

};

我使用的类具有通过从txt文件获取数据来计算用户的BMI的功能。但是,我不断收到以下错误:'calcBMI :: getHeight':非标准语法;使用“&”创建指向成员的指针

1 个答案:

答案 0 :(得分:1)

您需要在()getWheight;的末尾加上getHeight;

void calculateBMI()
{
    calcBMI a;

    a.getWeight();
    a.getHeight();
}