报错
-
- 如何解决C++编译报错 was not declared in this scope
- error: ‘xxxxx::xxx’ will be initialized after [-Werror=reorder]
- warning: deleting object of abstract class type 'XXXX' which has non-virtual destructor will cause undefined behaviour [-Wdelete-non-virtual-dtor]或者warning: deleting object of polymorphic class type which has non_virtual destructor
- std::bad_alloc异常
- Segmentation fault (core dumped)
- 对‘sem_init/sem_wait/sem_destroy’等未定义的引用
如何解决C++编译报错 was not declared in this scope
参考文章
遇到错误'xxx'was not declared in this scope
表明编译器在当前作用域内找不到xxx类型的定义,即使已经在头文件中定义了,也可能由于以下几个原因导致错误:
- 头文件包含问题:确保在使用xxx的源文件中正确的包含了xxx.hpp文件
#include "xxx.hpp"
#include "../xxx.hpp" //依赖文件在上一级目录里
#include "xxx.h"
- 头文件包含路径:如果xxx.hpp不在标准包含路径里,需要在编译命令中指定正确的路径,或在包含语句中使用相对或绝对路径
如下文的getch.h,就是自行编写的工具头文件,放到标准路径中后,就可以直接#include <getch.h>调用了 - 头文件循环依赖:如果xxx.hpp依赖于定义xxx的其他文件,而这些文件又反过来依赖于xxx.hpp,这可能会导致循环依赖问题。
- 命名空间问题:如果xxx是在某个命名空间内定义的,那么在使用