【发布时间】:2012-03-08 20:24:20
【问题描述】:
问题的标题是错误本身,但我也将其包括在下面:
error: argument of type ‘char (CharStack::)()const throw (CharStack::Underflow)’ does not match ‘char’
这是我正在使用的代码文件:
#include <iostream>
#include "CharStack.h"
using namespace std;
// returns top value on stack
// throws exception if empty
//
// O(n)
char CharStack::top() const throw( Underflow )
{
Elem * cur = head;
if( !empty() )
{
while( cur && cur -> next )
cur = cur -> next;
return cur -> info;
}
}
int main()
{
CharStack * stack = new CharStack();
char top = stack -> top;
stack -> push( 't' );
stack -> push( 'e' );
stack -> push( 's' );
stack -> push( 't' );
stack -> push( 'i' );
stack -> push( 'n' );
stack -> push( 'g' );
stack -> output( cout );
delete stack;
}
在头文件中,我定义了我使用的两个异常,作为我下面的示例:
public:
// exceptions
class Overflow{};
class Underflow{};
我认为这是因为我没有处理摘录,但在目前的情况下我不知道如何处理它。
谢谢
【问题讨论】:
标签: c++ exception-handling compile-time