如何获得抛出自定义异常的语法?

时间:2015-01-28 22:38:54

标签: c++ templates exception

有人可以向我解释如何编译这段代码吗?这里的语法错误是什么?

template <typename T>
class Queue
{
  public:
    class Overflow {};
};

template <typename T, typename QUEUE>
class Queue_Adapter : public Queue<T>
{
  public:
    void fun();
};

template<typename T, typename QUEUE>
void
Queue_Adapter<T, QUEUE>::fun()
{
  throw Queue<T>::Overflow();
}

int main()
{
  Queue_Adapter<int, int> tmp;
  tmp.fun();
  return 0;
}

我收到以下错误消息:

test.cpp:19:19: error: 'Overflow' does not refer to a value
  throw Queue<T>::Overflow();
        ~~~~~~~~~~^
test.cpp:25:7: note: in instantiation of member function 'Queue_Adapter<int,
      int>::fun' requested here
  tmp.fun();
      ^
test.cpp:5:11: note: declared here
    class Overflow {};
          ^
1 error generated.

(为了摆脱抱怨我的问题主要是代码的错误消息......)

0 个答案:

没有答案