是Visual Studio 2013还是什么????- "Identifier not found"
Is it Visual Studio 2013 or what???? - "Identifier not found"
我正在阅读Bjarne的-使用c++的原理和实践(我发现它对初学者非常有用,因为我是一个),并且有一个示例计算器。我键入它在书中具有的函数,但使用不同的组织:头文件。我有一个特别的问题:
#ifndef Primary_h
#define Primary_h
#include "std_lib_facilities.h"
#include "Token.h"
#include "Expression.h"
//Deal with numbers and parentheses
//USES:expression() and get_token
double primary(){
Token t = get_token();
switch (t.kind){
case '(':
{
double d = expression();
t = get_token();
if (t.kind != ')')
cerr << "')' expectedn";
return d;
}
case '8': return t.value;
default: cerr << "primary expectedn";
}
}
#endif
当我编译我得到:
error C3861: 'expression': identifier not found
尽管我添加了expression
头文件,它是:
#ifndef Expression_h
#define Expression_h
#include "std_lib_facilities.h"
#include "Token.h"
#include "Term.h"
//Deal with + and -
//USES: term() and get_token
double expression(){
double left = term(); //read and evaluate an expression
Token t = get_token(); //get the next token
switch (t.kind){ //see which kind of token it is
case '+': left += term(); t = get_token(); break; //read and evaluate a Term, then do an addition
case '-': left -= term(); t = get_token(); break; //read and evaluate a Term, then do a subtraction
default: return left; break; //return the value of the expression
}
}
#endif
正如你在expression
中看到的,我使用了另一个类似的头文件:Term.h
,它工作得很好(在编译中)。错误行用粗体表示。你能帮帮我吗?
像往常一样,这种"神奇的"行为很可能是(读:肯定是)由头文件的循环包含引起的。
Include保护符打破了无限递归,但这样做的一个副作用是,某些头文件第一眼看起来"包含",实际上并没有包含(被保护符跳过)。
在你的案例中,包括守卫完成了他们的工作,阻止了Expression.h
被适当地包含到Primary.h
中。这就是为什么expression
在Primary.h
中保持未声明的原因。
但是为什么你在头文件中写函数定义??我相信你不可能从比亚恩的书里得到这个想法。如果将函数定义移动到.cpp
文件中,并在头文件中仅留下声明,则问题将自行解决(尽管这不是以循环方式包含头文件的借口)。
你有一个循环依赖,请检查你所有的头文件和头保护,如果他们是正确的或不
相关文章:
- OpenCV Android C++ imwrite not found
- 解决"ld: library not found for -ltensorflow_framework.2.3.0"
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常
- C++初学者:为什么我的编译器根据我的循环返回"name not found"?
- 使用提升 asio 时出现"resolve: Host not found (authoritative)"异常
- 为什么 VScode 在 .h 文件中显示"'iostream' file not found"?
- 为什么我在" 'X' identifier not found' "上收到错误
- WinDBG适用于从Visual Studio 2015保存的转储,但不适用于任务管理器。显示异常代码"not found"
- "Entry Point Not Found" Azure 中的错误 LightGBM R 包
- TBB_tbb_LIBRARY_DEBUG-NOT FOUND
- 在 Ubuntu 16.04 下运行协程示例会得到"'experimental/coroutine' file not found"
- 在 mongodb c++ 驱动程序中使用声明"not found"
- 如何修复"/bin/sh: bc: command not found"
- CMake,QT Quick & Visual Studio:"qrc:/main.qml:-1 File not found"
- opencv aruco.h not found windows 10 visual studio
- Qt Cmake 错误编译"GuiSupportQt not found"
- 如何在C++的程序中显示Windows的"DLL not found"错误?
- 如何修复张量流中的"Non-OK-status: Not found: Op type not registered 'NoOp' in binary running"
- 如何在Xcode中修复'sh: brew: command not found'?
- OpenCV: reconstruct() not found