Я пытаюсь реализовать приоритетную очередь, используя связанный список, но у меня возникают проблемы с try / catch. Вот соответствующие части файла заголовка очереди с приоритетами:
#ifndef PRIORITYQUEUELINKED_H
#define PRIORITYQUEUELINKED_H
#include "RuntimeException.h"
#include <list>
using namespace std;
template <typename E, typename C> // uses data type and some total order relation
class PriorityQueueLinked {
// code for PriorityQueueLinked
class EmptyPriorityQueueException : public RuntimeException {
public:
EmptyPriorityQueueException() :
RuntimeException("Empty priority queue") {}
};
// more code
#endif
Вот заголовочный файл RuntimeException:
#ifndef RUNTIMEEXCEPTION_H_
#define RUNTIMEEXCEPTION_H_
#include <string>
class RuntimeException {// generic run-time exception
private:
std::string errorMsg;
public:
RuntimeException(const std::string& err) { errorMsg = err; }
std::string getMessage() const { return errorMsg; }
};
inline std::ostream& operator<<(std::ostream& out, const RuntimeException& e)
{
out << e.getMessage();
return out;
}
#endif
Вот мой главный:
#include "PriorityQueueLinked.h"
#include "Comparator.h"
#include <iostream>
using namespace std;
int main() {
try {
PriorityQueueLinked<int,isLess> prique; // empty priority queue
prique.removeMin(); // throw EmptyPriorityQueueException
}
catch(...) {
cout << "error" << endl << endl;
}
getchar();
return 0;
}
Моя проблема заключается в невозможности настроить замену для "..." для catch. Я пробовал несколько вещей, одна из них: «catch (PriorityQueueLinked :: EmptyPriorityQueueException E)», но в этом случае говорится, что EmptyPriorityQueueException не является членом PriorityQueueLinked. Любой совет будет принята с благодарностью.
Спасибо