C++ 错误:在';之前应为类名;{&èx27;令牌-似乎找不到任何循环包含

C++ 错误:在';之前应为类名;{&èx27;令牌-似乎找不到任何循环包含,c++,c++11,makefile,C++,C++11,Makefile,我知道这个问题已经被问了好几次,通常的情况是因为循环包含,但在过去的几个小时里,我一直很难找到循环包含的情况。我想我也没有办法向前声明任何东西。我可能错了,所以我需要一些帮助 我试图完成的分配使用两个ADT,一个是堆栈,另一个是队列。这些文件被模板化以接受任何数据类型,但在本实验室中,我们将使用字符串。我们的Queue.h/.hpp应该实现QueueInterface.h,Stack.h/.hpp应该实现StackInterface.h BuildingExecutive: main.o Exe

我知道这个问题已经被问了好几次,通常的情况是因为循环包含,但在过去的几个小时里,我一直很难找到循环包含的情况。我想我也没有办法向前声明任何东西。我可能错了,所以我需要一些帮助

我试图完成的分配使用两个ADT,一个是堆栈,另一个是队列。这些文件被模板化以接受任何数据类型,但在本实验室中,我们将使用字符串。我们的Queue.h/.hpp应该实现QueueInterface.h,Stack.h/.hpp应该实现StackInterface.h

BuildingExecutive: main.o Executive.o PreconditionViolationException.o
    g++ -std=c++11 -g -Wall main.o PreconditionViolationException.o Executive.o -o BuildingExecutive

main.o: main.cpp
    g++ -std=c++11 -g -Wall -c main.cpp

PreconditionViolationException.o: PreconditionViolationException.cpp PreconditionViolationException.h
    g++ -std=c++11 -g -Wall -c PreconditionViolationException.cpp

Executive.o: Executive.cpp Executive.h Queue.hpp Queue.h Stack.hpp Stack.h Node.hpp Node.h StackInterface.h QueueInterface.h
    g++ -std=c++11 -g -Wall -c Executive.cpp
最后,我们必须定义我们自己的名为PremissionViolationException的错误。h是std::runtime_error的一个子类

为了可能节省一些时间,我将从我正在使用的文件列表开始,然后是我的Makefile

Executive.h/.cpp,main.cpp,Node.h/.hpp predictionException.h/.cpp Queue.h/.hpp QueueInterface.h Stack.h/.hpp StackInterface.h

BuildingExecutive: main.o Executive.o PreconditionViolationException.o
    g++ -std=c++11 -g -Wall main.o PreconditionViolationException.o Executive.o -o BuildingExecutive

main.o: main.cpp
    g++ -std=c++11 -g -Wall -c main.cpp

PreconditionViolationException.o: PreconditionViolationException.cpp PreconditionViolationException.h
    g++ -std=c++11 -g -Wall -c PreconditionViolationException.cpp

Executive.o: Executive.cpp Executive.h Queue.hpp Queue.h Stack.hpp Stack.h Node.hpp Node.h StackInterface.h QueueInterface.h
    g++ -std=c++11 -g -Wall -c Executive.cpp
这就是关于我的Makefile的一个可能离题的问题。我的问题是我是否应该将PremissionViolationException.o编译为它自己的对象文件?我可以理解为什么我不显式编译堆栈和队列文件,因为它们是模板化的,但因为依赖PremissionViolationException的唯一文件是模板化文件,这有什么区别吗?我的执行程序(只是输出和运行程序的文件)不依赖于PredictionViolationException,它只捕获任何std::exception,它应该捕获PredictionViolationException,因为std::runtime\u error是std::exception的子类

如果我的Makefile没有明显的问题,下面是我如何尝试跟踪它是否有任何循环包含

我从main.cpp开始,它看起来像这样

#include "Executive.h"

int main(int argc, char** argv) {
  Executive exec(argv[1]);
  exec.Run();
  return 0;
}
这只包括Executive.h,所以这里是

#ifndef EXECUTIVE_H
#define EXECUTIVE_H

#include "Queue.h"
#include "Stack.h"

class Executive {
.
. will cutout whatever isn't necessary
.
private:
    Queue<std::string> Line;
    Stack<std::string> Elevator;
};
#endif
\ifndef执行官
#定义执行董事
#包括“Queue.h”
#包括“Stack.h”
班主任{
.
.将删除任何不必要的内容
.
私人:
排队线;
烟囱升降机;
};
#恩迪夫
这个文件依赖于Queue.h和Stack.h,下面是它们

#ifndef QUEUE_H
#define QUEUE_H

#include "Node.h"
#include "QueueInterface.h"

template <typename T>
class Queue : public QueueInterface {
.
.
.
};
#endif
\ifndef队列
#定义队列
#包括“Node.h”
#包括“QueueInterface.h”
模板
类队列:公共队列接口{
.
.
.
};
#恩迪夫
然后

#ifndef堆栈
#定义堆栈
#包括“Node.h”
#包括“StackInterface.h”
模板
类堆栈:公共堆栈接口{
.
.
.
};
我不认为Node会在这里造成问题,所以这里是接口

#ifndef STACKINTERFACE_H
#define STACKINTERFACE_H

#include "PreconditionViolationException.h"

template <typename T>
class StackInterface {
.
.
.
};
#endif
\ifndef STACKINTERFACE\u H
#定义堆栈接口
#包括“PrepositionViolationException.h”
模板
类堆栈接口{
.
.
.
};
#恩迪夫

\ifndef队列接口\u H
#定义队列接口
#包括“PrepositionViolationException.h”
模板
类队列接口{
.
.
.
}
#恩迪夫
其中每一个都包括PredictionViolationException,因为它们的方法可以引发该异常

#ifndef PVE_H
#define PVE_H

#include <stdexcept>
#include <string>

class PreconditionViolationException : public std::runtime_error {
.
.
.
}
#endif
\ifndef PVE\u H
#定义PVE_H
#包括
#包括
类预条件ViolationException:公共std::runtime\u错误{
.
.
.
}
#恩迪夫
如果我错了,请纠正我,但是在阅读之后,我认为除了在声明我的节点时,我没有其他地方可以向前声明任何内容。因为我对如何将所有内容编译在一起的理解不是最好的,我唯一能想到的是我的makefile不适合此任务,或者我ve通告包括我无法识别的内容

我花了很多时间试图追踪和理解正在发生的事情,所以我希望有一些东西能帮助我更好地理解正在发生的事情

抱歉,如果这太长了!非常感谢您的帮助!

模板
template<class T>
class Stack : public StackInterface {
类堆栈:公共堆栈接口{
StackInterface
不是类(它是类模板),因此不能从中继承

您可能打算从
StackInterface
继承,对于
QueueInterface

模板也是如此
类堆栈:公共堆栈接口{
StackInterface
不是类(它是类模板),因此不能从中继承


你可能想继承
StackInterface
,同样的
QueueInterface

啊……….duh。非常感谢。那之后我觉得有点傻。啊……….duh。非常感谢。那之后我觉得有点傻哈哈。
template<class T>
class Stack : public StackInterface {