遇到错误问题:在'{'之前,预期的非限定 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
#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
则不要包含它。
相关文章:
- C++,我收到一个无法理解的编译器错误
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 删除映射和分割错误中的一个过去结束元素
- 为什么我的 heap.h 文件给我一个LNK2001错误?
- 写一个分数类,我无法弄清楚这些错误
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- 一个标头库中的错误
- 给定一个整数数组,需要在Max_Heap上运行操作。得到错误"segmentation fault",有什么想法吗?(C++)
- 使用Visual Studio在虚幻引擎中创建一个新的类c ++给了我太多的错误
- 我正在尝试制作一个自平衡机器人,但编译时存在错误。我不知道如何解决它
- 试图修复一个错误,该错误不会让我开始编程其余部分
- MSVC 无法根据模板参数进行数学运算,这是一个错误吗?
- 我正在尝试一个傻瓜 C++ 练习,我遇到了一个错误,说类 'GraduateStudent' 没有任何名为 'advisor' 的字段
- 零四元数和任何向量都不为零的特征积,这是一个错误吗?
- 我有一个线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)错误.我认为这是由于内存管理不好.我可以
- 两个线程一个使用流 Api,另一个线程创建文件失败并出现错误ERROR_SHARING_VIOLATION
- 在使用堆栈为下一个最大数字编写代码时面临 SIGSEGV(分段错误)
- LNK2019错误一个DLL链接到MFC DLL
- 错误:一个声明中有多个类型
- 带有两个运算符的C++11模糊错误(一个左值-第二个右值).底部的