g++编译报错原因分析“was not declared in this scope"
来源:互联网 发布:怎样抢注域名 编辑:程序博客网 时间:2024/04/30 14:04
在编译程序的时候,提示:“was not declared in this scope"。
经过分析后发现原因如下:
1.变量、函数、或者类未声明或者定义。这是最简单的情况~却是我经常犯的错误(基本也是这几个原因中可能性最大的)
另外,网上有人指出以下原因也会导致该提示错误:
如果在file b中用到了file a中的变量、函数、类,那么由于#ifndef和#define的作用,file b中的#include <file a>语句执行时无法执行file a中的#include <file b>造成错误。
3.头文件起名字的时候不小心和库中的头文件重名了,而在程序中又用了这个库的这个头文件。
这样, 就造成宏重名了,一定有一个头文件因为 #ifndef失去了效果。别的文件自然找不到这个头文件中的声明,就提示 was not decleared in this scope了
经过分析后发现原因如下:
1.变量、函数、或者类未声明或者定义。这是最简单的情况~却是我经常犯的错误(基本也是这几个原因中可能性最大的)
另外,网上有人指出以下原因也会导致该提示错误:
2.头文件相互#include时,导致了依赖关系错误。比如,头文件形成了一个环形依赖,
/***file a ****/#ifndef FILE_A_#define FILE_A_#include <file b>#endif /****file b ***/#ifndef FILE_B_#define FILE_B_#include <file a>#endif
如果在file b中用到了file a中的变量、函数、类,那么由于#ifndef和#define的作用,file b中的#include <file a>语句执行时无法执行file a中的#include <file b>造成错误。
3.头文件起名字的时候不小心和库中的头文件重名了,而在程序中又用了这个库的这个头文件。
这样, 就造成宏重名了,一定有一个头文件因为 #ifndef失去了效果。别的文件自然找不到这个头文件中的声明,就提示 was not decleared in this scope了
1 0
- g++编译报错原因分析“was not declared in this scope"
- 报错null was not declared in this scope
- 关于g++ memcpy’ was not declared in this scope解决方法
- C++ 报'vector' was not declared in this scope错误
- [编译错误]:exit was not declared in this scope
- ardupilot编译出错:'__builtin_bswap16' was not declared in this scope
- ‘cout’ was not declared in this scope
- 'wxCHANGE_DIR' was not declared in this scope
- 'setenv' was not declared in this scope
- 'UINT64_C' was not declared in this scope
- ‘UINT64_C’ was not declared in this scope
- ‘close’ was not declared in this scope
- was not declared in this scope
- Connect was not declared in this scope
- 'XXX' was not declared in this scope
- getcwd was not declared in this scope
- nullptr was not declared in this scope
- ‘close’ was not declared in this scope
- 欢迎使用CSDN-markdown编辑器
- Python 中的进程、线程、协程、同步、异步、回调
- x264中的cpu-a.asm
- ssh服务相关问题
- HTTP请求包文格式
- g++编译报错原因分析“was not declared in this scope"
- [c++]list 测试
- Java面试(JavaWeb部分)
- [Leetcode] Balanced Binary Tree
- html5新特性
- error LNK2011
- 【编程语言】Python 异常 TclError: no display name and no $DISPLAY environment variable
- HDU5898 oddeven 数位DP
- uva 195Anagram