错误:“页面”未在此范围内声明
error: ‘Page’ was not declared in this scope
我有以下 c++ 类:
页.h:
#ifndef PAGE_H_
#define PAGE_H_
#include "Process.h"
class Page {
public:
Page();
virtual ~Page();
Process *process;
};
#endif /* PAGE_H_ */
和进程.h:
#ifndef PROCESS_H_
#define PROCESS_H_
#include <vector>
#include "Page.h"
class Process {
public:
Process();
virtual ~Process();
int size;
double life_remaining;
std::vector<Page> pages;
};
#endif /* PROCESS_H_ */
编译时出现以下错误:
../src/Process.h:21:14: error: ‘Page’ was not declared in this scope
../src/Process.h:21:18: error: template argument 1 is invalid
../src/Process.h:21:18: error: template argument 2 is invalid
我该如何纠正?当我注释掉以下行时:#include"Proccess.h"和"流程";然后编译。当我删除评论时,它给了我错误
使用前向声明而不是包含在Page.h
中:
//replace this:
//#include "Process.h"
//with this:
class Process;
class Page {
public:
Page();
virtual ~Page();
Process *process;
};
您在 Process
和 Page
之间有一个循环依赖关系。
而不是。。。
#include "Process.h"
。在Page.h中,向前声明...
class Process;
。这将使您在Page
class
中拥有Process* process;
。
我认为Process.h首先包含在Page.h中,而不是Process.h中的Page.h。
相关文章:
- 错误:未在此范围内声明'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'未在此范围内声明