简体   繁体   English

未声明的标识符自定义类

[英]Undeclared identifier custom class

'Plansza' : undeclared identifier I don't know why i get this error. 'Plansza' : undeclared identifier我不知道为什么会收到此错误。 I have 2 classes called "Plansza" and "GameData", i have included both headers( in Plansza.h included "GameData.h" and it's works, but when I include "Plansza.h" in GameData.h it does not see Plansza class :S 我有两个名为“ Plansza”和“ GameData”的类,我同时包含了两个标头(在Plansza.h中包括了“ GameData.h”,并且可以使用,但是当我在GameData.h中包括“ Plansza.h”时,看不到普兰莎课:S

When you include Ah in Bh and ALSO the other way around, you setup a circular dependence . 当您在Bh包含Ah以及在其他方式中也包含ALSO时,您将设置循环依赖 If you had include guards, one of them gets lost and such errors occur. 如果您包括警卫, 其中的一名将迷路,并且会发生此类错误。

What you want to do is try hard to include .h files in the .cpp files as far as possible, and if this is not possible, reduce the 2 way dependence into a 1 way dependence. 您想要做的是尝试将.h文件尽可能地包含在.cpp文件中,如果无法做到,则将2种方式的依赖减少为1种方式的依赖。

Try as often as possible to use forward declarations in the .h files, as long as you are using only pointers to the class, this will suffice. 只要您仅使用指向类的指针,就应尽可能多地尝试在.h文件中使用前向声明

class Plansza;

instead of 代替

#include "Plansza.h"

Edit: Thanks user1701595 for a very good reference - Organizing Code Files in C and C++ 编辑:感谢user1701595提供了很好的参考- 在C和C ++中组织代码文件

如果任何人发现了这个问题,并且具有周期性包括,我设法通过命名枚举情况下,同样的事情为我的类名来得到这个确切的同样的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM