gpt4 book ai didi

c++ - 非标准语法;使用 '&' 创建一个指针成员。显示函数 C++ 出错

转载 作者:太空宇宙 更新时间:2023-11-04 15:58:41 24 4
gpt4 key购买 nike

我正在尝试获取一个显示函数来保存来自 float 的信息,当我尝试运行该程序时,它给出了错误“非标准语法;使用‘&’创建指针成员”,然后我将'&'添加到 float 并使它们成为指针,它给了我错误“'&':对绑定(bind)成员函数表达式的非法操作。我不知道为什么它不起作用。

这是我的代码:

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;


class Rectangle
{

public:

//constructor
Rectangle() { }


//accessor
float GetHeight() { return m_height; } const
float GetWidth() { return m_width; } const

float GetArea() { return m_height * m_width; }

float GetPerimeter() { return m_height + m_height + m_width + m_width; }

//mutator
void SetHeight(float h)
{
cout << "Please Enter height: \n";
cin >> h;

};

void SetWidth(float w)
{
cout << "Please Enter the width: \n";
cin >> w;
}


void Display()
{
cout << "Height: " << GetHeight << " " << "Width: " << GetWidth << " " << "Area: " << GetArea << " " << "Perimeter: " << GetPerimeter << endl;

};



private:

float m_height;
float m_width;

};



using namespace std;

int main()
{
Rectangle r;
float height = 0;
float width = 0;
r.SetHeight(height);
r.SetWidth(width);

r.Display();





_getch();
return 0;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com