非标准语法,使用 & 创建指向成员的指针
Non-standard syntax, use & to create a pointer to member
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":非标准语法;使用"&"创建指向成员的指针
你需要在getWheight;
末尾()
,getHeight;
void calculateBMI()
{
calcBMI a;
a.getWeight();
a.getHeight();
}
相关文章:
- 从成员指针到整个结构/类的强制转换
- OOP 中的单成员指针
- 使用结构成员指针在C++中填充结构
- 聚合初始化,将成员指针设置为同一结构成员
- 空指针常量 (nullptr)、空指针值和空成员指针值之间有什么区别?
- 共享 C++ 的数据成员指针
- 如何声明指向成员内容的成员指针m_pmd/m_pmf并访问它们?
- 从类C++外部调用指向成员方法的成员指针
- 结构成员指针是否自动初始化为零?
- 如何删除类内类类型的类成员指针
- 是否打印指向已定义 int 的成员指针
- 指向常量的成员指针
- 通过此指针访问时的成员差异和自身的成员指针(简单的 QT 示例问题)
- 类数据成员指针的非类型模板参数包无法使用 gcc 编译
- 为什么我不能在同一行中定义两个相同类型的类的成员指针
- 将类成员指针传递给 Lambda 捕获列表 c++11
- 在单一实例类中将成员指针设置为 null 的正确方法是什么
- 无法删除在destructor中的成员指针的课程
- 删除对象而不调用成员指针的析构函数
- 当派生类的基类具有成员指针时,对其进行深层复制