C++ VS 2019 预期出现“}”错误,但代码运行良好

时间:2021-06-06 21:08:53

标签: c++ visual-studio-2019

我使用 Visual Studio 2019 社区版编写此代码只是为了练习,但在代码的最后一行我不断收到“预期的 '}'”错误。当我单击运行时,它运行良好。这是为什么?

这是完整的代码。

#include <iostream>
#include <string>

using namespace std;

void funSayHi();

class People
{
public:
    void callPeople(string x, int y, double z)
    {
        ResName = x;
        ResAge = y;
        ResHight = z;

        cout << ResName << endl << ResAge << endl << ResHight << endl;
    }

private:
    string ResName = "No Name";
    int ResAge = 0;
    double ResHight = 0;
};

int main()
{
    string name;
    int age;
    double hight;

    funSayHi();

    cout << "Enter name\n";
    cin >> name;
    cout << "Enter age\n";
    cin >> age;
    cout << "Enter hight\n";
    cin >> hight;

    People peopleObj;
    peopleObj.callPeople(name, age, hight);   
}

void funSayHi()
{
    cout << "Hi\n";
} //VS 19 underlines this bracket and says "expected '}'"

0 个答案:

没有答案