交叉依赖项类的问题
Problems with cross dependency classes
我对这部分代码有问题。 编译器说我不能使用指向未完成类的指针。 我已经尝试在图类中使用包括板类和在板中使用图,但这会导致编译器出现严重问题,并且出现了一大堆错误。(#pragma 一次和/或头球中的守卫被使用(
//Board.h
class Figure;
class Board
{
Figure *sz[8][8];
...
public:
void showRange();
friend class Figure;
};
//-------------------
//Board.cpp
void Board::showRange()
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if(sz[j][i])
sz[j][i]->range();
}
}
this->display();
}
...
//Figure.h
class Board;
class Figure
{
protected:
Board *s;
int x, y;
public:
virtual void range() = 0;
friend class Board;
};
//range funcions are defined in member classes
[编辑1] 将 figure.h 添加到 board.h 编译器错误 C2027 在图.cpp和成员类文件中
Severity Code Description Project File Line Suppression State
Error C2027 use of undefined type 'Board' ..figure.cpp 7
Error C2027 use of undefined type 'Board' ..figure.cpp 15
Error C2027 use of undefined type 'Board' ..figure.cpp 17
Error C2027 use of undefined type 'Board' ..figure.cpp 25
Error C2027 use of undefined type 'Board' ..figure.cpp 26
Error C2027 use of undefined type 'Board' ..bishop.cpp 7
Error C2027 use of undefined type 'Board' ..bishop.cpp 13
Severity Code Description Project File Line Suppression State
Error (active) E0393 pointer to incomplete class type is not allowed ..Figure.cpp 7
Error (active) E0393 pointer to incomplete class type is not allowed ..Figure.cpp 15
Error (active) E0393 pointer to incomplete class type is not allowed ..Figure.cpp 17
Error (active) E0393 pointer to incomplete class type is not allowed ..Figure.cpp 26
Error (active) E0393 pointer to incomplete class type is not allowed ..Figure.cpp 25
Board.cpp
必须#include "Figure.h"
,否则编译器不知道Figure
对象range
方法(在Board.cpp中调用(。
顺便问一下:你为什么需要朋友声明? 它通常表明设计不佳。
相关文章:
- node-gyp 的先有鸡还是先有蛋的问题:指向依赖项中的头文件
- 在包含窗口标头时难以解决循环依赖关系问题
- C++ 中的循环依赖关系问题
- 交叉依赖项类的问题
- "std::shared_ptr"循环依赖关系是如何导致问题的
- 生成的依赖项问题
- C++ API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL依赖项问题
- 这是静态库依赖树中的菱形问题吗?
- 是库依赖问题可以通过接口避免
- C 如何在Typedef模板和类之间修复依赖关系问题
- 另一个模板循环依赖问题
- 命名空间内类的循环依赖问题
- 交叉编译助推 1.60.0 内部依赖问题
- CMAKE:目标依赖项存在问题(add_dependency不起作用?
- 显式模板专用化和依赖名称查找问题
- DLL 无法加载:0x8007007E找不到模块。不确定导致此依赖项问题的原因
- 使用发布 CRT 在调试中构建应用程序,并在提升时存在依赖问题
- WindowsCE 依赖关系问题随着算法的变化而消失
- 我在一个简单的参数依赖查找/模板类型推断问题方面遇到问题
- 视觉C++在解决循环依赖关系时遇到了设计问题