我正在处理在C++中创建异常的问题,我有以下测试代码:
#include <iostream>
#include <stdexcept>
#include <new>
using namespace std;
class Myerror : public runtime_error {
private:
string errmsg;
public:
Myerror(const string &message): runtime_error(message) { }
};
int main(int argc, char *argv[]) {
throw Myerror("wassup?");
}我编制这份报告的目的是:
icpc -std=c++11 -O3 -m64
在编辑时,我会收到这样的警告:
ld:警告:在_main中直接访问全局弱符号__ZN7MyerrorD1Ev意味着弱符号不能在运行时被覆盖。这可能是由于使用不同的可见性设置编译不同的翻译单位造成的。
如果使用g++而不是icpc,则不会收到此警告。
我无法理解这意味着什么,以及是什么导致了这个警告的产生。代码按预期运行,但是我想要取消和正在发生的事情。
发布于 2013-03-18 14:19:01
尝试以下几点:
#include <iostream>
#include <stdexcept>
#include <new>
using namespace std;
class Myerror : public runtime_error {
public:
Myerror(const string &message) throw(): runtime_error(message) { }
virtual ~Myerror() throw() {}
};
int main(int argc, char *argv[]) {
throw Myerror("wassup?");
}为什么需要未使用的字符串错误?
https://stackoverflow.com/questions/15402243
复制相似问题