was not declared in this scop

Posted weixin_35827498

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了was not declared in this scop相关的知识,希望对你有一定的参考价值。

在写一个非常简单的程序的时候,提示:“was not declared 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>语句将失去效果。

3.我遇到的情况:我在给头文件起名字的时候不小心和某个库中的头文件重名了,而在程序中又用来了这个库的这个头文件。这样, #ifndef XXXX 和 #ifndef XXXX中的宏重名了,我自己写的头文件就失去了效果。别的文件自然找不到这个头文件中的声明,就提示 was not decleared in this scope了

今天在Ubuntu10.04下做build oms1.5的时候,报了这么一个错误: 
frameworks/base/tools/aidl/AST.cpp:10: error: 'fprintf' was not declared in this scope 

后来发现本机的gcc g++ 是4.4版,安装4.3, 重新链接,问题解决。 

apt-get install gcc-4.3 g++-4.3 

进入/usr/bin 

cd /usr/bin 

建个软连接 

ln -s gcc-4.3 gcc 

ln -s g++-4.3 g++ 

然后进入android目录下,执行make,就可以了


以上是关于was not declared in this scop的主要内容,如果未能解决你的问题,请参考以下文章

[Error] 'strlen' was not declared in this scope

[Error] 'strlen' was not declared in this scope

C++ error: ‘shared_ptr’ was not declared in this scope

C++ error: ‘shared_ptr’ was not declared in this scope

QTerror: 'connect'/'sender' was not declared in this scope

vscode c++编译报错:‘nullptr’ was not declared in this scope(-std=c++11)