C++ &引用;使用未声明的标识符“;当文件#包含在Xcode中时
我正在设计一个纸牌游戏程序 其中,StartStack是一副牌,StartCard是从牌组底部开始的牌,AnimalCard和ActionCard是可以添加到牌组中的牌类型。然而,我在Xcode中遇到了一些非常奇怪的错误 以下是我的课程: StartStack.hpp:C++ &引用;使用未声明的标识符“;当文件#包含在Xcode中时,c++,xcode,undeclared-identifier,C++,Xcode,Undeclared Identifier,我正在设计一个纸牌游戏程序 其中,StartStack是一副牌,StartCard是从牌组底部开始的牌,AnimalCard和ActionCard是可以添加到牌组中的牌类型。然而,我在Xcode中遇到了一些非常奇怪的错误 以下是我的课程: StartStack.hpp: #ifndef StartStack_hpp #define StartStack_hpp // Imports of other classes #include "AnimalCard.h" #include "Start
#ifndef StartStack_hpp
#define StartStack_hpp
// Imports of other classes
#include "AnimalCard.h"
#include "StartCard.hpp"
class ActionCard;
// Imports of frameworks
#include <deque>
#include <stdio.h>
#include <memory>
class StartStack : public AnimalCard{
private:
deque<shared_ptr<AnimalCard> > sstack;
StartCard scard;
public:
StartStack();
StartStack& operator+= ( std::shared_ptr<ActionCard> );
StartStack& operator-= ( std::shared_ptr<ActionCard> );
std::shared_ptr<StartCard> getStartCard();
char getAnimals(int);
std::shared_ptr<ActionCard> pop_front() { return sstack.pop_front(); }
std::shared_ptr<ActionCard> remove_front();
};
此类的错误:
- 第21行(在“public:”和“virtualQueryResult query()=0;”-空行之间)我得到了“未知类型名称表”
我已经调查了Xcode中的相关错误,没有发现与我遇到的问题相关的任何问题。如果有人能提出一些可能有用的建议,我们将不胜感激。您所有的标题都缺少一个
#endif
。这是复制错误吗?否则这可能是源代码…这是一个复制错误,我的程序中有这些错误。例如,如果“NoSplit.hpp”#include
s“StartStack.hpp”,可能会发生这种情况。请记住,#include
仅表示“在此处插入此文件的内容”,它并不比这更聪明。发生这种情况可能是因为您有循环引用;我的意思是,你不能引用一个使用你当前正在使用的类的类。
#ifndef StartCard_hpp
#define StartCard_hpp
// Imports of other classes
#include "NoSplit.hpp"
// Imports of frameworks
#include <stdio.h>
#include <deque>
class StartCard : public NoSplit{
public:
StartCard();
char getAnimals(int index){return c;};
};
// Imports of other classes
#include "QueryResult.hpp"
#include "Player.hpp"
#include "NoSplit.hpp"
#include "Table.hpp"
class ActionCard : public NoSplit{
public:
virtual QueryResult query() = 0;
virtual void perform(Table&, Player*, QueryResult ) = 0;
};