遇到错误问题:在'{'之前,预期的非限定 id 只是一个我需要的类的标头,只是不确定导致错误的原因

Having trouble with the error: expected unqualfied-id before '{' just a header for a class that I need just not sure what is causing the error

本文关键字:错误 一个 不确定 id 之前 问题 遇到      更新时间:2023-10-16
#include <iostream>
using namespace std;
  {
    class book
    {
    public: 
        set_book();
        show_book();
    private:
        string title,author;
        int pages,date;
    };  
  }

除了其他答案提出的观点...

你有:

    set_book();
    show_book();

这些不是有效的成员函数声明。它们至少需要一个返回类型。

    void set_book();
    void show_book();

请添加他们所需的任何输入参数。

您缺少包含 ( string (,您应该避免在标题中using namespace std

并且,删除此额外范围:

using namespace std;
// { <------
class book
{
public: 
    set_book();
    show_book();
private:
    string title,author;
    int pages,date;
};  
// } <------

你有一组虚假的{}

更改为:

#include <iostream>
using namespace std;   // this is a bad idea BTW
class book
{
// etc.
此外,最好

#include <string>以防包含您的文件的人不包含该文件;如果您实际上没有使用iostream则不要包含它。

相关文章: