错误:"任何类"未在此范围内声明
error: ‘whatever class' was not declared in this scope
main 包含:
#include "num.h"
num * intObj = new num;
数字H包含:
#ifndef __EXPR_H__
#define __EXPR_H__
#include <string>
class num : public Expr {
//
};
#endif
Expr.H包含:
#ifndef __EXPR_H__
#define __EXPR_H__
#include <string>
class Expr {
public:
virtual int eval() const = 0;
virtual std::string prettyPrint() const = 0;
virtual ~Expr();
};
#endif
然后我得到:
error: ‘num’ was not declared in this scope
num * intObj = new num;
^
这是什么原因呢?我还在不同的 .h 文件中声明了类 Expr,该文件也包含在 main 中。
我声明和正在使用的所有新类都遇到相同的错误。
> 您对两个标头使用相同的标头保护__EXPR_H__
。将仅定义一个。
将num.h
中的__EXPR_H__
更改为__NUM_H__
,就会没事的。
尝试以下操作之一:
#include "expr.h" /* before num.h */
#include "num.h"
num * intObj = new num;
或
#ifndef __NUM_H__ /* Header file guard for num.h not expr.h here */
#define __NUM_H__
#include <string>
include "expr.h" /* #ifndef __EXPR_H and #define __EXPR_H__ in this .h file */
class num : public Expr {
//
};
#endif
相关文章:
- 错误:未在此范围内声明'reverse'
- 错误:"imread"未在此范围内声明
- 未在此范围内声明错误 'xy'
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- C++ 在编译过程中 strtok 函数 Eclipse 说没有在范围内声明?
- 'num1'未在此范围内声明
- 如何找到在本地范围内声明的变量的地址?
- NT状态未在此范围内声明
- 变量未在此范围内声明 数组线性搜索
- 包含文件中的 Typdef "未在此范围内声明"
- 'ClassName'和'ClassInstance'未在此范围内声明
- C++ 中的类之间的数据重新循环 - 错误:'<class name>'未在此范围内声明
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 如何修复错误:"vreinterpretq_u32_f64"未在此范围内声明 - 在Android上使用Eigen构建
- 如何修复C++中的"arrStud未在此范围内声明"错误
- 错误:"SHGetKnownFolderPath"未在此范围内声明
- 错误:'Sprite'未在此范围内声明