gpt4 book ai didi

c++ - 错误 : ‘Page’ was not declared in this scope

转载 作者:行者123 更新时间:2023-11-30 00:57:01 25 4
gpt4 key购买 nike

我有以下 C++ 类:

页面.h:

#ifndef PAGE_H_
#define PAGE_H_

#include "Process.h"

class Page {
public:
Page();
virtual ~Page();
Process *process;
};

#endif /* PAGE_H_ */

和Process.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"和 Process *process;然后编译。当我删除评论时,它给我错误

最佳答案

Page.h 中使用前向声明而不是包含:

//replace this:
//#include "Process.h"

//with this:
class Process;

class Page {
public:
Page();
virtual ~Page();
Process *process;
};

关于c++ - 错误 : ‘Page’ was not declared in this scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9164859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com