开发者社区> 问答> 正文

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

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。但是,我得到以下错误:‘calsionbmi::getHL.8’:非标准语法;使用‘&’来创建指向成员的指针

展开
收起
aqal5zs3gkqgc 2019-12-06 21:24:56 2501 0
1 条回答
写回答
取消 提交回答
  • 你需要()在.的末尾getWheight; 和 getHeight;

    void calculateBMI()
    {
        calcBMI a;
    
        a.getWeight();
        a.getHeight();
    }
    
    2019-12-06 21:25:33
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载