好吧,发生在我身上的事情真的很奇怪,但我会尽量说清楚。我有一个类,在一种方法中我决定抛出一个(在 hpp 定义和 cpp 实现中)。所以我有可以抛出 std::exception 的方法。这里没有问题。
我创建了一个例外:
class MyException : public std::exception {
public:
MyException() throw();
~MyException() throw();
const char what() const throw();
}
好的,让我们在我的方法中使用它:
class myclass {
void mymethod() throw(std::exception);
}
到:
class myclass {
void mymethod() throw(MyException); // I have included hpp file where MyException is defined
}
好的!这就是我得到的
/tmp/ccwSS5GE.o:(.gcc_except_table+0x84): undefined reference to 'typeinfo for MyException' collect2: ld 返回 1 exit status
为什么??使用 std::exception 一切正常,现在一切正常。